gpt4 book ai didi

ios - 如何解决像 'NULL cString' 这样的崩溃?

转载 作者:行者123 更新时间:2023-11-29 05:32:55 25 4
gpt4 key购买 nike

使用 AVSpeechUtterance 设置语音时发生崩溃。有像 'NULL cString'

这样的崩溃

为了防止出现空字符串,我在开头进行了判断。代码如下:

- (void)speakString:(NSString *)string{
if (SQ_Str_IsEmpty(string)) {
return;
}

if (self.speech){
AVSpeechUtterance *aUtterance = [AVSpeechUtterance speechUtteranceWithString:string];
[aUtterance setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]];
aUtterance.rate = 0.53;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0){
aUtterance.rate = 0.25;
}
else if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0)
{
aUtterance.rate = 0.23;
}
if ([self.speech isSpeaking])
{
[self.speech stopSpeakingAtBoundary:AVSpeechBoundaryWord];
}
[self.speech speakUtterance:aUtterance];
}
}

但我们仍然可以收到一些用户的崩溃报告。崩溃日志如下:


#28 Thread

NSInvalidArgumentException

*** +[NSString stringWithUTF8String:]: NULL cString

解析原始
0 CoreFoundation ___exceptionPreprocess + 228
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation -[NSCache init]
3 Foundation +[NSString stringWithUTF8String:] + 92
4 TTSSpeechBundle TTSSpeechServerCopyVoiceNamesForLanguage + 15772
5 libsystem_pthread.dylib __pthread_body + 128
6 libsystem_pthread.dylib _pthread_start + 44
7 libsystem_pthread.dylib thread_start + 4

我发现崩溃不会发生在主线程

最佳答案

你的判断方法正确吗?我们在字符串传递过程中使用它。

#define SafetyStr(obj)     (obj == nil ? @""  : obj)
[self speakString:SafetyStr(obj)];

关于ios - 如何解决像 'NULL cString' 这样的崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57353003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com