我正在呼唤法语语言的文字。
此功能按预期工作:iOS 9.3
模拟器,iOS 9.3
设备(iPad 3rd gen
(,iOS 10.3
模拟器。在iOS 10.3
设备(iPhone 6s
(上(默默地(不起作用。
默认法语语音已安装并根据设备设置工作。
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];
}
结果,语音合成器由铃声卷(而不是媒体卷(控制。铃声在测试仪的设备上被静音。
在您的.h文件上添加AVSpeechSynthesizer* synthesizer = NULL;
而且您很好 - 我已经测试了。
转到您的.h文件并添加
AVSpeechSynthesizer* synthesizer = NULL;
和.m一个
-(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];
}