Submit Search
AVSpeechSynthesizerとロケール
4 likes
6,992 views
T
toyship
Cookpad Potatotips #1 で発表しました。
Technology
Read more
1 of 11
Download now
Download to read offline
1
2
3
4
5
6
7
8
9
10
11
More Related Content
PPTX
15分でできるAmazon Alexa Skill開発
拓哉 中山
PDF
Downalodable Storyboard
Yuta Tokoro
PDF
Bluetooth LEとiBeaconを使った、すれ違い通信
幸雄 村上
PDF
アプリのバックグラウンド処理 | iOS 7エンジニア勉強会
Yahoo!デベロッパーネットワーク
PDF
Time for Xcode Behavior
toyship
PDF
Notifications in iOS10
toyship
PDF
Universal Link
toyship
PDF
Can we live in a pure Swift world?
toyship
15分でできるAmazon Alexa Skill開発
拓哉 中山
Downalodable Storyboard
Yuta Tokoro
Bluetooth LEとiBeaconを使った、すれ違い通信
幸雄 村上
アプリのバックグラウンド処理 | iOS 7エンジニア勉強会
Yahoo!デベロッパーネットワーク
Time for Xcode Behavior
toyship
Notifications in iOS10
toyship
Universal Link
toyship
Can we live in a pure Swift world?
toyship
More from toyship
(11)
PDF
Swift Protocol and Selector
toyship
PDF
What's new Swift3
toyship
PDF
Xcode7時代のアプリ配布
toyship
PDF
My first tvOS
toyship
PDF
3D touch for iOS
toyship
PDF
Contents blocker on iOS9
toyship
PDF
Embedded framework and so on
toyship
PDF
はじめてのWKInterfaceController
toyship
PDF
App extension for iOS
toyship
PDF
サーバーからiOSアプリを変更する
toyship
PDF
Xcode bot
toyship
Swift Protocol and Selector
toyship
What's new Swift3
toyship
Xcode7時代のアプリ配布
toyship
My first tvOS
toyship
3D touch for iOS
toyship
Contents blocker on iOS9
toyship
Embedded framework and so on
toyship
はじめてのWKInterfaceController
toyship
App extension for iOS
toyship
サーバーからiOSアプリを変更する
toyship
Xcode bot
toyship
Ad
AVSpeechSynthesizerとロケール
1.
AVSpeechSynthesizerとロケール @TachibanaKaoru 2013/11/13
2.
自己紹介 • @TachibanaKaoru • http://www.toyship.org/ •
渋谷の genesix で働く iOSエンジニア。 • 個人的にはこんなアプリを作ったりしています。 Toy Jigsaw • Cookpad歴 11年 ( http://cookpad.com/kitchen/18627)
3.
AVSpeechSynthesizerとは • iOS7から導入されたAPIが公開された音声読み上げ機能。 • 文字列を与えると読み上げをしてくれます。 •
delegateを使うと、「今読んでいる単語」なども取り 出せます。 • 詳しい使い方はこちら。 • https://github.com/toyship/StoryTeller • http://www.toyship.org/archives/1483
4.
ロケールの設定 • 文章を正しく読ませるためには、AVSpeechSynthesizerに読み上げる文の言語 に対応したロケール(NSLocale)を設定しないと正しく読み上げてくれません。 • AVSpeechSynthesizerが文章の言語を自動判別してくれるわけではありませ ん。 •
今のところ、36個のロケールに対応しています。 ! ! ! ! ! ! ! ! ! AVSpeechSynthesizer* mySpeechSynthesizer = [[AVSpeechSynthesizer alloc] init]; mySpeechSynthesizer.delegate = self; NSString* targetText = @"Hello World!"; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:targetText]; AVSpeechSynthesisVoice* englishVoice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; utterance.voice = englishVoice; [myspeechSynthesizer speakUtterance:utterance];
5.
でも言語判定めんどくさいよね……。 Web APIは有料だし……。
6.
システムの挙動は…… • iOSの純正アプリ(メールなど)では選択した文章 に応じて、ちゃんと適切に言語を判断。 • 例えばiPhoneのシステムロケールを日本語にした 状態でも、英語の文章を選択すると英語の声で読 んでくれます。
7.
探したらありました、NSStringの言語判定 • CFStringTokenizerCopyBestStringLanguageを利用 ! ! CFStringRef
text = (CFStringRef)CFBridgingRetain(self.inputText.text); ! CFRange range = CFRangeMake(0, CFStringGetLength(text)); ! NSString *language = (NSString*)CFBridgingRelease(CFStringTokenizerCopyBestStringLanguage(text, range));
8.
CFStringTokenizerCopyBestStringLanguage仕様 • 指定した文字列の言語コードを返す。判別にはおよそ200から400文字が必 要。 • 30言語を判別可能。(アラビア語、ブルガリア語、チェコ語、デンマーク 語、ドイツ語、ギリシャ語、英語、スペイン語、フィンランド語、フランス 語、ヘブライ語、クロアチア語、ハンガリー語、アイスランド語、イタリア 語、日本語、韓国語、ノルウェー語、オランダ語、ポーランド語、ポルトガ ル語、ルーマニア語、ロシア語、スロバキア語、スウェーデン語、タイ語、 トルコ語、ウクライナ語、簡体中国語、繁体中国語) •
でも実際の判別はちょっと微妙かも……。
9.
AVSpeechSynthesizer Tips • AVSpeechSynthesizerを使うときには、 CFStringTokenizerCopyBestStringLanguageを使って文 章の言語判定をしましょう!
10.
おまけその1 • なぜ、AVSpeechSynthesizerに指定するのは言語コードではなくて、ロケール のなんでしょうか。言語だけ指定すれば読んでくれるんじゃない?という気 もしますが……。 • ヒント:「12/3/2012」をen-GB(イギリス英語)とen-US(アメリカ英 語)で読ませてみてください。
11.
おまけその2 • AVSpeechSynthesizerに設定する「ロケール」ですが、iPhoneでは、システム 言語とシステムロケールとは別々に設定できますよね。 • 例えばシステムの言語は日本語だけど、ロケールはen-GBになっていた場合は AVSpeechSynthesizerのロケールはどうなるでしょうか。 •
ja-JPになります。 • システム言語とシステムロケールを言語を優先してAVSpeechSynthesizer のデフォルトロケールが決定されるようです。([NSLocale currentLocale] がAVSpeechSynthesizerのデフォルトロケールではないことに注意。)
Download