iOS 10.3 text to speech works on simulator but not on device

若如初见. 提交于 2019-12-11 09:16:37

问题


I'm calling text to speech for the French language.

This works as expected on: iOS 9.3 simulator, iOS 9.3 device (iPad 3rd gen), iOS 10.3 simulator. Does not work (silently) on iOS 10.3 device (iPhone 6s).

Default French voice is installed and works according to device settings.

static AVSpeechSynthesizer* synthesizer = NULL;
//...
+(void)readText:(NSString*)text
{
    if(synthesizer == NULL)
      synthesizer = [[AVSpeechSynthesizer alloc] init];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"fr-FR"];
    [synthesizer speakUtterance:utterance];
}

回答1:


Turns out the speech synthesizer is controlled by the ringer volume, not the media volume. The ringer was muted on the tester's device.




回答2:


on your .h file add AVSpeechSynthesizer* synthesizer = NULL; and you're good to go-- i have tested it.. it works super fine :)

go to your .h file and add

AVSpeechSynthesizer* synthesizer = NULL;

and on the .m one

-(void)readText:(NSString*)text
{
    if(synthesizer == NULL)
      synthesizer = [[AVSpeechSynthesizer alloc] init];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"fr-FR"];
    [synthesizer speakUtterance:utterance];
}


来源:https://stackoverflow.com/questions/44255097/ios-10-3-text-to-speech-works-on-simulator-but-not-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!