首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AVSpeechSynthesizer不能在真正的iOS9设备上与日本人一起工作

AVSpeechSynthesizer不能在真正的iOS9设备上与日本人一起工作
EN

Stack Overflow用户
提问于 2015-10-17 07:41:08
回答 1查看 229关注 0票数 1

我可以使用AVSpeechSynthesizer API进行文本到语音,在模拟器上讲日语,但它并不能在真正的设备上工作,产生日志,如下所示。有什么建议吗?

AXSpeechAssetDownloader\ error \ ASAssetQuery错误获取结果(用于com.apple.MobileAsset.MacinTalkVoiceAssets)错误Domain=ASError Code=21“无法复制资产信息”UserInfo={NSDescription=Unable到复制资产信息}

这是来源

代码语言:javascript
复制
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:speechStr];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ja-JP"];
[self.synthesizer speakUtterance:utterance]
EN

回答 1

Stack Overflow用户

发布于 2016-06-30 11:46:09

首先,您必须检查是否启用了setting>accessibilty>speech>speech选择,只需在ios 9或greater.then中启用它,这是我的工作代码,如果它对您有帮助的话。

代码语言:javascript
复制
 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];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33184132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档