Ios 我试图获取AVSpeechSynthesizer音频文件,但它给了我一个错误,;线程1:异常:“;avspeechouter不得排队两次”;
这是我的密码:Ios 我试图获取AVSpeechSynthesizer音频文件,但它给了我一个错误,;线程1:异常:“;avspeechouter不得排队两次”;,ios,objective-c,Ios,Objective C,这是我的密码: _avSpeaker = [[AVSpeechSynthesizer alloc] init]; speeechutterance = [[AVSpeechUtterance alloc] initWithString:textViewStr]; AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]; speeechutterance.voice
_avSpeaker = [[AVSpeechSynthesizer alloc] init];
speeechutterance = [[AVSpeechUtterance alloc] initWithString:textViewStr];
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
speeechutterance.voice = voice;
[_avSpeaker speakUtterance:speeechutterance];
__block AVAudioFile *output = nil;
if (@available(iOS 13.0, *)) {
[_avSpeaker writeUtterance:speeechutterance
toBufferCallback:^(AVAudioBuffer * _Nonnull buffer) {
AVAudioPCMBuffer *pcmBuffer = (AVAudioPCMBuffer*)buffer;
if (!pcmBuffer) {
NSLog(@"Error");
return;
}
if (pcmBuffer.frameLength != 0) {
//append buffer to file
if (output == nil) {
output = [[AVAudioFile alloc] initForWriting:[NSURL fileURLWithPath:alawFilePathName]
settings:pcmBuffer.format.settings
commonFormat:AVAudioPCMFormatInt16
interleaved:NO error:nil];
}
[output writeFromBuffer:pcmBuffer error:nil];
}
}];
} else {
}
。。。。。。。。。。
如何解决这个问题以及如何使用函数“WriteTerance”请有人能帮我吗?我也遇到过同样的问题。