问题
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