gpt4 book ai didi

ios - AVSpeechSynthesizer 语音未改变

转载 作者:行者123 更新时间:2023-11-29 05:12:13 28 4
gpt4 key购买 nike

我正在使用**AVSpeechSynthesizer**,以下是将文本传递给**AVSpeechSynthesizer**的代码。

func speakOutText(_ textToRead:String ){
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
try audioSession.setMode(AVAudioSessionModeDefault)
try audioSession.setActive(true, with: .notifyOthersOnDeactivation)
} catch {
print("audioSession properties weren't set because of an error.")
}
let speakUtterance = AVSpeechUtterance.init(string: textToRead);
speakUtterance.voice = AVSpeechSynthesisVoice(language: "en-IN")
speakUtterance.pitchMultiplier = 1.2
speakUtterance.rate = 0.5
speechSynthesizer.speak(speakUtterance)

}

它正在用女性声音正确地朗读文本。

但是如果我在设置 -> Siri 和搜索 -> Siri 语音 -> 性别(男)中更改男声。再次调用 speakOutText 方法,它仅以女声朗读文本,而不以男声朗读文本。

谁能告诉我原因,为什么它没有变成男声

最佳答案

Can anyone please let me know the reason, why it is not changing to a male voice?

SiriAVSpeechSynthesizer 声音不同,并且不在设置中的同一位置(iOS 13.3) :

  • Siri设置Siri 和搜索语言Siri 语音 .
  • AVSpeechSynthesizer设置辅助功能语音内容声音

But if I change male voice in settings -> Siri & Search -> Siri Voice -> Gender(Male)... it is speaking the text in female voice only, not in a male voice.

AVSpeechSynthesisVoiceGender属性只是一个 setter/getter ,不能帮助你改变性别声音。
为此,您必须通过设置指定要使用的确切语音(参见上面的观点),或者如果需要的话以编程方式指定:注意当前语言代码(AVSpeechSynthesisVoice.currentLanguageCode ()) 在您的应用中使用,因为如果您不真正更改发音,它将被视为默认值。

编写以下代码(iOS 13,Swift 5.1):

let allVoices =  AVSpeechSynthesisVoice.speechVoices()

var index = 0
for theVoice in allVoices {
print("Voice[\(index)] = \(theVoice)\n")
index += 1
}

...将显示您设备上的所有可用语音: enter image description here

指示此列表中的语音发音以获得适当的语音性别

结论:更改 AVSpeechSynthesizer 语音与 Siri 无关,即使可以在适应当前语言代码的设置中完成,除非所有内容都以编程方式指定。

关于ios - AVSpeechSynthesizer 语音未改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59573787/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com