首页 文章

如何在swift中添加/更改语音语音性别到iOS应用程序?我正在使用AVSpeechSynthesisvoice Class来获取语音

提问于
浏览
7

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

我想要实现的下一件事是添加语音性别,以便用户可以在 Siri app中切换默认的 MaleFemale 语音 . 我不想让它变得复杂,只是寻找默认的男性或女性声音 .

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

我能改变它吗?我在应用程序设置页面上放置了一个 UIPickerView ,以便在男声和女声之间进行选择 .

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

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

1 回答

  • 0
    //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;
        }
    

相关问题