¿Cómo get una list de TODAS las voces en iOS 9?

La forma estándar de get una list de los objects 'todos' AVSpeechSynthesisVoice es pedirla:

[AVSpeechSynthesisVoice speechVoices] 

Sin embargo, esto solo muestra una única voz pnetworkingeterminada por par de idioma-región. por ejemplo para en-US:

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

Si miro en la aplicación Configuración en General → Accesibilidad → Habla → Voces → Inglés veo que tengo 'Siri Hembra (Mejorado)' seleccionado, pero esa voz no se puede seleccionar del código. La list completa es

1

Entonces, la gran pregunta es: ¿cómo selecciono, por ejemplo, Alex o Siri Female como una voz del código?

Fondo

  • AVSpeechSynthesisVoice documentation AVSpeechSynthesisVoice .

  • Los idiomas para las voces deben especificarse en formatting BCP-47. Vea a continuación las voces disponibles, (y lo que significan sus códigos de lenguaje BCP-47 correspondientes).

Voces respaldadas

A partir del 28 de abril de 2017, print(AVSpeechSynthesisVoice.speechVoices()) informa las siguientes voces compatibles:

 [AVSpeechSynthesisVoice 0x6080000097d0] Language: ar-SA, Name: Maged, Quality: Default [com.apple.ttsbundle.Maged-compact] [AVSpeechSynthesisVoice 0x608000009780] Language: cs-CZ, Name: Zuzana, Quality: Default [com.apple.ttsbundle.Zuzana-compact] [AVSpeechSynthesisVoice 0x608000009440] Language: da-DK, Name: Sara, Quality: Default [com.apple.ttsbundle.Sara-compact] [AVSpeechSynthesisVoice 0x608000009670] Language: de-DE, Name: Anna, Quality: Default [com.apple.ttsbundle.Anna-compact] [AVSpeechSynthesisVoice 0x6080000092e0] Language: el-GR, Name: Melina, Quality: Default [com.apple.ttsbundle.Melina-compact] [AVSpeechSynthesisVoice 0x608000009310] Language: en-AU, Name: Karen, Quality: Default [com.apple.ttsbundle.Karen-compact] [AVSpeechSynthesisVoice 0x6080000098d0] Language: en-GB, Name: Daniel, Quality: Default [com.apple.ttsbundle.Daniel-compact] [AVSpeechSynthesisVoice 0x6080000094e0] Language: en-IE, Name: Moira, Quality: Default [com.apple.ttsbundle.Moira-compact] [AVSpeechSynthesisVoice 0x6080000096b0] Language: en-US, Name: Samantha, Quality: Default [com.apple.ttsbundle.Samantha-compact] [AVSpeechSynthesisVoice 0x608000009480] Language: en-ZA, Name: Tessa, Quality: Default [com.apple.ttsbundle.Tessa-compact] [AVSpeechSynthesisVoice 0x6080000093d0] Language: es-ES, Name: Monica, Quality: Default [com.apple.ttsbundle.Monica-compact] [AVSpeechSynthesisVoice 0x6080000096c0] Language: es-MX, Name: Paulina, Quality: Default [com.apple.ttsbundle.Paulina-compact] [AVSpeechSynthesisVoice 0x608000009550] Language: fi-FI, Name: Satu, Quality: Default [com.apple.ttsbundle.Satu-compact] [AVSpeechSynthesisVoice 0x6080000094f0] Language: fr-CA, Name: Amelie, Quality: Default [com.apple.ttsbundle.Amelie-compact] [AVSpeechSynthesisVoice 0x608000009880] Language: fr-FR, Name: Thomas, Quality: Default [com.apple.ttsbundle.Thomas-compact] [AVSpeechSynthesisVoice 0x608000009290] Language: he-IL, Name: Carmit, Quality: Default [com.apple.ttsbundle.Carmit-compact] [AVSpeechSynthesisVoice 0x608000009570] Language: hi-IN, Name: Lekha, Quality: Default [com.apple.ttsbundle.Lekha-compact] [AVSpeechSynthesisVoice 0x608000009510] Language: hu-HU, Name: Mariska, Quality: Default [com.apple.ttsbundle.Mariska-compact] [AVSpeechSynthesisVoice 0x608000009040] Language: id-ID, Name: Damayanti, Quality: Default [com.apple.ttsbundle.Damayanti-compact] [AVSpeechSynthesisVoice 0x6080000096a0] Language: it-IT, Name: Alice, Quality: Default [com.apple.ttsbundle.Alice-compact] [AVSpeechSynthesisVoice 0x6080000092b0] Language: ja-JP, Name: Kyoko, Quality: Default [com.apple.ttsbundle.Kyoko-compact] [AVSpeechSynthesisVoice 0x608000009540] Language: ko-KR, Name: Yuna, Quality: Default [com.apple.ttsbundle.Yuna-compact] [AVSpeechSynthesisVoice 0x6080000090e0] Language: nl-BE, Name: Ellen, Quality: Default [com.apple.ttsbundle.Ellen-compact] [AVSpeechSynthesisVoice 0x608000009380] Language: nl-NL, Name: Xander, Quality: Default [com.apple.ttsbundle.Xander-compact] [AVSpeechSynthesisVoice 0x608000009240] Language: no-NO, Name: Nora, Quality: Default [com.apple.ttsbundle.Nora-compact] [AVSpeechSynthesisVoice 0x6080000090f0] Language: pl-PL, Name: Zosia, Quality: Default [com.apple.ttsbundle.Zosia-compact] [AVSpeechSynthesisVoice 0x608000009250] Language: pt-BR, Name: Luciana, Quality: Default [com.apple.ttsbundle.Luciana-compact] [AVSpeechSynthesisVoice 0x6080000094d0] Language: pt-PT, Name: Joana, Quality: Default [com.apple.ttsbundle.Joana-compact] [AVSpeechSynthesisVoice 0x608000009210] Language: ro-RO, Name: Ioana, Quality: Default [com.apple.ttsbundle.Ioana-compact] [AVSpeechSynthesisVoice 0x608000009130] Language: ru-RU, Name: Milena, Quality: Default [com.apple.ttsbundle.Milena-compact] [AVSpeechSynthesisVoice 0x608000009620] Language: sk-SK, Name: Laura, Quality: Default [com.apple.ttsbundle.Laura-compact] [AVSpeechSynthesisVoice 0x608000009730] Language: sv-SE, Name: Alva, Quality: Default [com.apple.ttsbundle.Alva-compact] [AVSpeechSynthesisVoice 0x608000009740] Language: th-TH, Name: Kanya, Quality: Default [com.apple.ttsbundle.Kanya-compact] [AVSpeechSynthesisVoice 0x6080000095e0] Language: tr-TR, Name: Yelda, Quality: Default [com.apple.ttsbundle.Yelda-compact] [AVSpeechSynthesisVoice 0x608000009010] Language: zh-CN, Name: Ting-Ting, Quality: Default [com.apple.ttsbundle.Ting-Ting-compact] [AVSpeechSynthesisVoice 0x608000009660] Language: zh-HK, Name: Sin-Ji, Quality: Default [com.apple.ttsbundle.Sin-Ji-compact] [AVSpeechSynthesisVoice 0x608000009860] Language: zh-TW, Name: Mei-Jia, Quality: Default [com.apple.ttsbundle.Mei-Jia-compact] 

Como Axello comenta a continuación, esto evidentemente no incluye la voz masculina en-AU que está disponible en las preferences de iPhone, "Lee". Parece que actualmente no está disponible a través de esta API. Tal vez se agregará a time, pero dado que las voces disponibles no parecen haber cambiado desde el 30 de diciembre de 2015 , no aguanto la respiración.

Preparar

 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. 

Responder

Podemos seleccionar la voz de Alex directamente, utilizando AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex) , pero curiosamente el único identificador que Apple ha proporcionado hasta la date es para Alex. 🤷

Para cualquier otra voz (vea la list anterior nuevamente para los nombres de voz), use el siguiente código:

 // 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 } } } 

(Esto podría hacerse de manera más elegante usando filter() que un bucle, pero no estoy familiarizado con la syntax en Swift, así que consulte aquí si está interesado, o deje un comentario si sabe cómo escribirlo).

En cuanto a las voces labeldas como 'Siri', no tengo ni idea. Tal vez no estén relacionados con AVSpeechSynthesisVoice ? Los comentarios son bienvenidos si conoces el trato que se respalda.