- PVSM.RU - https://www.pvsm.ru -
В iOS7 встроили синтезатор речи, теперь заставить свое приложение говорить вопрос пары строчек кода.
За синтез речи отвечает класс AVSpeechSynthesizer [1] Достаточно передать ему текст обернутый в класс AVSpeechUtterance [2] и текст будет прочитан смартфоном.
Голос зависит от локали, в том числе поддерживается русский. Речь звучит четко и приятно.
var speechSynthesizer = new AVSpeechSynthesizer ();
var speechUtterance =
new AVSpeechUtterance ("Shall we play a game?");
speechSynthesizer.SpeakUtterance (speechUtterance);
голос по умолчанию с английской локалью [3]
Это ссылка! Кликайте с Ctrl или Cmd, на хабре нельзя встроить звук. В нашем блоге разместил пост [4] с виджетами Sound Cloud.
Речь настраивается с помощью параметров класса AVSpeechUtterance:
На мой взгляд, текст по умолчанию звучит слишком быстро. Установим максимальную скорость уменьшенную в 3.6 раза
var speechSynthesizer = new AVSpeechSynthesizer ();
var speechUtterance =
new AVSpeechUtterance ("Shall we play a game?") {
Rate = AVSpeechUtterance.MaximumSpeechRate / (float)3.6
};
speechSynthesizer.SpeakUtterance (speechUtterance);
голос по умолчанию, макс скорость/3.6 [6]
Синтезатор речи в iOS7 поддерживает только женский голос в 35 локалях, среди них — русская.
['ar-SA', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-IE', 'en-US', 'en-ZA', 'es-ES', 'es-MX', 'fi-FI', 'fr-CA', 'fr-FR', 'hi-IN', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', 'nl-BE', 'nl-NL', 'no-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sv-SE', 'th-TH', 'tr-TR', 'zh-CN', 'zh-HK', 'zh-TW']
var speechSynthesizer = new AVSpeechSynthesizer ();
var speechUtterance =
new AVSpeechUtterance ("Сыграем в игру?") {
Rate = AVSpeechUtterance.MaximumSpeechRate / (float)4,
Voice = AVSpeechSynthesisVoice.FromLanguage ("ru-RU")
};
speechSynthesizer.SpeakUtterance (speechUtterance);
русский, четверть макс скорости [7]
Русский голос звучит прекрасно, попробуем проиграть длинный текст.
Лермонтов «Парус», русский, четверть макс скорости [8]
Есть огрехи, но на мой взгляд прекрасно. Подходит для боего использования.
Варианты приложений с синтезом речи:
В Android синтез речи [10] появился в 2009 году (1.6+), звучит отвратительно [11].
Автор: junk
Источник [13]
Сайт-источник PVSM.RU: https://www.pvsm.ru
Путь до страницы источника: https://www.pvsm.ru/mobile-development/47527
Ссылки в тексте:
[1] AVSpeechSynthesizer: https://developer.apple.com/library/ios/DOCUMENTATION/AVFoundation/Reference/AVSpeechSynthesizer_Ref/Reference/Reference.html
[2] AVSpeechUtterance: https://developer.apple.com/library/ios/DOCUMENTATION/AVFoundation/Reference/AVSpeechUtterance_Ref/Reference/Reference.html
[3] Image: https://soundcloud.com/touch-instinct/speak-default#t=0:01
[4] пост: http://touchin.ru/blog/post/text-to-speech-ios7/
[5] AVSpeechSynthesisVoice: https://developer.apple.com/library/ios/DOCUMENTATION/AVFoundation/Reference/AVSpeechSynthesisVoice_Ref/Reference/Reference.html#//apple_ref/occ/clm/AVSpeechSynthesisVoice/voiceWithLanguage:
[6] Image: https://soundcloud.com/touch-instinct/default-slow#t=0:02
[7] Image: https://soundcloud.com/touch-instinct/russian-slow#t=0:01
[8] Image: https://soundcloud.com/touch-instinct/russian-parus#t=0:01
[9] iBeacon: http://habrahabr.ru/company/touchinstinct/blog/195104/
[10] синтез речи: http://developer.android.com/reference/android/speech/tts/TextToSpeech.html
[11] звучит отвратительно: http://www.youtube.com/watch?v=uX9nt8Cpdqg#t=6m57s
[12] хабра-блог: http://habrahabr.ru/company/touchinstinct/
[13] Источник: http://habrahabr.ru/post/198808/
Нажмите здесь для печати.