【问题标题】:How can i add/change speech voice gender to iOS app in swift? I am using AVSpeechSynthesisvoice Class for getting speech voices如何在 swift 中向 iOS 应用程序添加/更改语音语音性别?我正在使用 AVSpeechSynthesisvoice 类来获取语音
【发布时间】:2016-06-24 11:25:10
【问题描述】:

我使用AVSpeechSynthesizer 创建了一个具有语音功能的应用程序,并在 TableView 中显示来自AVSpeechSynthesisVoice: speechVoices() 函数的语言列表。用户可以从 TableView 中选择语音语言。

我想要实现的下一个目标是添加语音性别,以便用户可以在默认的 男性 或 女性 语音之间切换,例如 Siri应用程序。我不想让它变得复杂,所以只是寻找默认的男声或女声。

从speechVoices() 返回的声音具有特定于每个声音的默认男声或女声。

我可以改变它吗?我在应用设置页面上放置了UIPickerView 以在男声和女声之间进行选择。

但是,我做了一些研究,但找不到任何文档。似乎在最新的 iOS 版本之前没有这样的支持。

到目前为止,有没有人尝试过实现这样的功能?

【问题讨论】:

  • 有人可以评论或分享一些想法吗?
  • 我也在想同样的事情!你(或某人)有没有想过这个问题?

标签: ios swift text-to-speech speech-synthesis avspeechsynthesizer


【解决方案1】:
    //NSArray* voices = AVSpeechSynthesisVoice.speechVoices;
    //voice identifier inspection reports
    //com.apple.ttsbundle.Samantha-compact
    //com.apple.speech.synthesis.voice
    //AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:text];
    //Replace hard-coded name with any available in the list pulled from the speechVoices array

    NSUInteger idx = [AVSpeechSynthesisVoice.speechVoices indexOfObjectPassingTest:^BOOL(AVSpeechSynthesisVoice * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
      return [obj.identifier containsString:@"Samantha"];
    }];
    if (idx > -1) {
      AVSpeechSynthesisVoice* voice = AVSpeechSynthesisVoice.speechVoices[idx];
      utterance.voice = voice;
    }

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    相关资源
    最近更新 更多