gpt4 book ai didi

ios - 如何在 iOS 9 上获取所有声音的列表?

转载 作者:技术小花猫 更新时间:2023-10-29 11:17:29 44 4
gpt4 key购买 nike

获取“所有”AVSpeechSynthesisVoice 对象列表的标准方法是请求它:

[AVSpeechSynthesisVoice speechVoices]

但是,这只会显示每个语言区域对的唯一默认语音。例如对于 en-US:

"Language: en-US, Name: Samantha, Quality: Default",

如果我在“设置”应用中查看一般 → 辅助功能 → 语音 → 语音 → 英语我看到我选择了“Siri Female (Enhanced)”,但无法从代码中选择该声音。完整列表是

1

所以最大的问题是:我该如何选择,例如Alex 或 Siri Female 作为来自代码的声音?

最佳答案

背景

  • AVSpeechSynthesisVoice documentation页面。

  • 语音的语言应以 BCP-47 格式指定。请参阅下面的可用语音(以及它们对应的 BCP-47 语言代码的含义)。

支持的语音

截至 2020 年 5 月 7 日,print(AVSpeechSynthesisVoice.speechVoices()) 报告了以下支持的语音(iOS 13.3.1;iPhone 而不是模拟器):

[AVSpeechSynthesisVoice 0x28266f9c0] Language: ar-SA, Name: Maged, Quality: Default [com.apple.ttsbundle.Maged-compact]
[AVSpeechSynthesisVoice 0x28266dd10] Language: cs-CZ, Name: Zuzana, Quality: Default [com.apple.ttsbundle.Zuzana-compact]
[AVSpeechSynthesisVoice 0x28266f050] Language: da-DK, Name: Sara, Quality: Default [com.apple.ttsbundle.Sara-compact]
[AVSpeechSynthesisVoice 0x28266ef90] Language: de-DE, Name: Anna, Quality: Default [com.apple.ttsbundle.Anna-compact]
[AVSpeechSynthesisVoice 0x28266f710] Language: de-DE, Name: Helena, Quality: Default [com.apple.ttsbundle.siri_female_de-DE_compact]
[AVSpeechSynthesisVoice 0x28266d8f0] Language: de-DE, Name: Martin, Quality: Default [com.apple.ttsbundle.siri_male_de-DE_compact]
[AVSpeechSynthesisVoice 0x28266fbf0] Language: el-GR, Name: Melina, Quality: Default [com.apple.ttsbundle.Melina-compact]
[AVSpeechSynthesisVoice 0x28266f9b0] Language: en-AU, Name: Catherine, Quality: Default [com.apple.ttsbundle.siri_female_en-AU_compact]
[AVSpeechSynthesisVoice 0x28266ea00] Language: en-AU, Name: Gordon, Quality: Default [com.apple.ttsbundle.siri_male_en-AU_compact]
[AVSpeechSynthesisVoice 0x28266f5e0] Language: en-AU, Name: Karen, Quality: Default [com.apple.ttsbundle.Karen-compact]
[AVSpeechSynthesisVoice 0x28266e9a0] Language: en-GB, Name: Arthur, Quality: Default [com.apple.ttsbundle.siri_male_en-GB_compact]
[AVSpeechSynthesisVoice 0x28266fba0] Language: en-GB, Name: Daniel, Quality: Default [com.apple.ttsbundle.Daniel-compact]
[AVSpeechSynthesisVoice 0x28266f880] Language: en-GB, Name: Martha, Quality: Default [com.apple.ttsbundle.siri_female_en-GB_compact]
[AVSpeechSynthesisVoice 0x28266d0e0] Language: en-IE, Name: Moira, Quality: Default [com.apple.ttsbundle.Moira-compact]
[AVSpeechSynthesisVoice 0x28266efe0] Language: en-IN, Name: Rishi, Quality: Default [com.apple.ttsbundle.Rishi-compact]
[AVSpeechSynthesisVoice 0x2826327e0] Language: en-US, Name: Aaron, Quality: Default [com.apple.ttsbundle.siri_male_en-US_compact]
[AVSpeechSynthesisVoice 0x28266fb40] Language: en-US, Name: Fred, Quality: Default [com.apple.speech.synthesis.voice.Fred]
[AVSpeechSynthesisVoice 0x28266ce30] Language: en-US, Name: Nicky, Quality: Default [com.apple.ttsbundle.siri_female_en-US_compact]
[AVSpeechSynthesisVoice 0x28266ed60] Language: en-US, Name: Samantha, Quality: Default [com.apple.ttsbundle.Samantha-compact]
[AVSpeechSynthesisVoice 0x28266f170] Language: en-ZA, Name: Tessa, Quality: Default [com.apple.ttsbundle.Tessa-compact]
[AVSpeechSynthesisVoice 0x28266ef60] Language: es-ES, Name: Mónica, Quality: Default [com.apple.ttsbundle.Monica-compact]
[AVSpeechSynthesisVoice 0x28266ed30] Language: es-MX, Name: Paulina, Quality: Default [com.apple.ttsbundle.Paulina-compact]
[AVSpeechSynthesisVoice 0x28266d2d0] Language: fi-FI, Name: Satu, Quality: Default [com.apple.ttsbundle.Satu-compact]
[AVSpeechSynthesisVoice 0x28266fe40] Language: fr-CA, Name: Amélie, Quality: Default [com.apple.ttsbundle.Amelie-compact]
[AVSpeechSynthesisVoice 0x28266f620] Language: fr-FR, Name: Daniel, Quality: Default [com.apple.ttsbundle.siri_male_fr-FR_compact]
[AVSpeechSynthesisVoice 0x28266fbc0] Language: fr-FR, Name: Marie, Quality: Default [com.apple.ttsbundle.siri_female_fr-FR_compact]
[AVSpeechSynthesisVoice 0x28266fb20] Language: fr-FR, Name: Thomas, Quality: Default [com.apple.ttsbundle.Thomas-compact]
[AVSpeechSynthesisVoice 0x28266fd30] Language: he-IL, Name: Carmit, Quality: Default [com.apple.ttsbundle.Carmit-compact]
[AVSpeechSynthesisVoice 0x28266d820] Language: hi-IN, Name: Lekha, Quality: Default [com.apple.ttsbundle.Lekha-compact]
[AVSpeechSynthesisVoice 0x28266f070] Language: hu-HU, Name: Mariska, Quality: Default [com.apple.ttsbundle.Mariska-compact]
[AVSpeechSynthesisVoice 0x28266ed70] Language: id-ID, Name: Damayanti, Quality: Default [com.apple.ttsbundle.Damayanti-compact]
[AVSpeechSynthesisVoice 0x282631210] Language: it-IT, Name: Alice, Quality: Default [com.apple.ttsbundle.Alice-compact]
[AVSpeechSynthesisVoice 0x28266ef30] Language: ja-JP, Name: Hattori, Quality: Default [com.apple.ttsbundle.siri_male_ja-JP_compact]
[AVSpeechSynthesisVoice 0x28266d510] Language: ja-JP, Name: Kyoko, Quality: Default [com.apple.ttsbundle.Kyoko-compact]
[AVSpeechSynthesisVoice 0x28266e840] Language: ja-JP, Name: O-ren, Quality: Default [com.apple.ttsbundle.siri_female_ja-JP_compact]
[AVSpeechSynthesisVoice 0x28266ea90] Language: ko-KR, Name: Yuna, Quality: Default [com.apple.ttsbundle.Yuna-compact]
[AVSpeechSynthesisVoice 0x28266f6e0] Language: nl-BE, Name: Ellen, Quality: Default [com.apple.ttsbundle.Ellen-compact]
[AVSpeechSynthesisVoice 0x28266f6a0] Language: nl-NL, Name: Xander, Quality: Default [com.apple.ttsbundle.Xander-compact]
[AVSpeechSynthesisVoice 0x28266dc80] Language: no-NO, Name: Nora, Quality: Default [com.apple.ttsbundle.Nora-compact]
[AVSpeechSynthesisVoice 0x28266d020] Language: pl-PL, Name: Zosia, Quality: Default [com.apple.ttsbundle.Zosia-compact]
[AVSpeechSynthesisVoice 0x28266e930] Language: pt-BR, Name: Luciana, Quality: Default [com.apple.ttsbundle.Luciana-compact]
[AVSpeechSynthesisVoice 0x28266e1b0] Language: pt-PT, Name: Joana, Quality: Default [com.apple.ttsbundle.Joana-compact]
[AVSpeechSynthesisVoice 0x28266cfb0] Language: ro-RO, Name: Ioana, Quality: Default [com.apple.ttsbundle.Ioana-compact]
[AVSpeechSynthesisVoice 0x28266ee50] Language: ru-RU, Name: Milena, Quality: Default [com.apple.ttsbundle.Milena-compact]
[AVSpeechSynthesisVoice 0x28266eee0] Language: sk-SK, Name: Laura, Quality: Default [com.apple.ttsbundle.Laura-compact]
[AVSpeechSynthesisVoice 0x28266e070] Language: sv-SE, Name: Alva, Quality: Default [com.apple.ttsbundle.Alva-compact]
[AVSpeechSynthesisVoice 0x28266d470] Language: th-TH, Name: Kanya, Quality: Default [com.apple.ttsbundle.Kanya-compact]
[AVSpeechSynthesisVoice 0x28266f1d0] Language: tr-TR, Name: Yelda, Quality: Default [com.apple.ttsbundle.Yelda-compact]
[AVSpeechSynthesisVoice 0x28266db10] Language: zh-CN, Name: Tian-Tian (Enhanced), Quality: Enhanced [com.apple.ttsbundle.Ting-Ting-premium]
[AVSpeechSynthesisVoice 0x28266d890] Language: zh-CN, Name: Li-mu, Quality: Default [com.apple.ttsbundle.siri_male_zh-CN_compact]
[AVSpeechSynthesisVoice 0x28266d4c0] Language: zh-CN, Name: Tian-Tian, Quality: Default [com.apple.ttsbundle.Ting-Ting-compact]
[AVSpeechSynthesisVoice 0x28266ea60] Language: zh-CN, Name: Yu-shu, Quality: Default [com.apple.ttsbundle.siri_female_zh-CN_compact]
[AVSpeechSynthesisVoice 0x28266f140] Language: zh-HK, Name: Sin-Ji, Quality: Default [com.apple.ttsbundle.Sin-Ji-compact]
[AVSpeechSynthesisVoice 0x28266ef10] Language: zh-TW, Name: Mei-Jia, Quality: Default [com.apple.ttsbundle.Mei-Jia-compact]
[AVAlexSpeechSynthesisVoice 0x282630950] Language: en-US, Name: Alex, Quality: Enhanced [com.apple.speech.voice.Alex]

正如 Axello 在下面评论的那样,这显然不包括 iPhone 首选项中可用的 en-AU 男声“Lee”。看起来他目前无法通过此 API 访问。也许他会及时添加,但考虑到可用的声音看起来并​​没有改变 since 30th December 2015 ,我不会为此屏住呼吸。

设置

import AVFoundation

let utterance : AVSpeechUtterance = AVSpeechUtterance(string: "String to be read out.")
let voiceToUse: AVSpeechSynthesisVoice? = AVSpeechSynthesisVoice(language: "en-US")
utterance.voice = voiceToUse! // Set voice by BCP-47 language code.
AVSpeechSynthesizer().speak(utterance) // Note: Won't be heard in Swift Playground.

回答

我们可以使用 AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex) 直接选择 Alex 的声音,但奇怪的是,Apple 迄今为止提供的唯一标识符是 Alex。 🤷

对于任何其他语音(请再次查看上面的语音名称列表),使用以下代码:

// From https://www.ikiapps.com/tips/2015/12/30/setting-voice-for-tts-in-ios
var voiceToUse: AVSpeechSynthesisVoice?
for voice in AVSpeechSynthesisVoice.speechVoices() {
if #available(iOS 9.0, *) {
if voice.name == "Karen" {
voiceToUse = voice
}
}
}

(这可以使用 filter() 比循环更优雅地完成,但我不熟悉 Swift 中的语法,所以如果有兴趣请引用 here,或者离开如果你知道如何写评论)。

至于标有“Siri”的声音,我不知道。也许它们与 AVSpeechSynthesisVoice 无关?如果您知道背后的交易,欢迎发表评论。

关于ios - 如何在 iOS 9 上获取所有声音的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35492386/

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