我有一个以下代码:
NSString *str = nil;
currentUtterance = [[AVSpeechUtterance alloc] initWithString: str];
[_speechSynthesizer speakUtterance:currentUtterance];我想问为什么这段代码没有抛出任何异常?取而代之的是,didFinishSpeechUtterance代表在演讲结束后调用。
发布于 2019-02-21 09:03:35
头文件中的参数有时比文档中包含的信息更多。initWithString:不符合要求_Nonnull参数的条件。当传递一个nil时,它会生成一个有效的空语句。语音合成器勇敢地工作着。你听不到的声音就是什么都没说的声音。
如果您的应用程序需要将其视为错误状态,它可以检查nil和throw its own exception的str。
https://stackoverflow.com/questions/54797394
复制相似问题