AVSpeechSynthesizer无法在iOS9的真实设备上使用日语

时间:2015-10-17 07:41:09

标签: ios9

我可以使用AVSpeechSynthesizer API将文本转语音在模拟器上说日语,但它不能用于生成日志的真实设备,如下所示。有什么建议吗?

  

AXSpeechAssetDownloader |误差| ASAssetQuery错误获取结果   (对于com.apple.MobileAsset.MacinTalkVoiceAssets)错误域= ASError   代码= 21“无法复制资产信息”   UserInfo = {NSDescription =无法复制资产信息}

这是来源

AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:speechStr];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ja-JP"];
[self.synthesizer speakUtterance:utterance]

1 个答案:

答案 0 :(得分:1)

首先,您必须检查设置> accessibilty>语音>语音选择是否启用,只需在ios 9或更高版本中启用它。然后, 这是我的工作代码,如果它对你有用的话。

 NSMutableString *mutableString = [self.utteranceString mutableCopy];
  //  CFStringTransform((__bridge CFMutableStringRef)mutableString, NULL, kCFStringTransformToLatin, NO);
    //CFStringTransform((__bridge CFMutableStringRef)mutableString, NULL, kCFStringTransformStripCombiningMarks, NO);

    AVAudioSessionCategoryPlayback error:&setCategoryErr];
    AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:self.utteranceString];
    [synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:@"ja-JP"];
    self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
    self.speechSynthesizer.delegate = self;
     // set your class to conform to the AVSpeechSynthesizerDelegate protocol
      float speechSpeed = 0.5f;
      [synUtt setRate:speechSpeed];
      UInt32 doChangeDefaultRoute = 1;

    UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    [synUtt setVolume:1.0];
    [self.speechSynthesizer speakUtterance:synUtt];