Download free for 30 days
Sign in
Upload
Language (EN)
Support
Business
Mobile
Social Media
Marketing
Technology
Art & Photos
Career
Design
Education
Presentations & Public Speaking
Government & Nonprofit
Healthcare
Internet
Law
Leadership & Management
Automotive
Engineering
Software
Recruiting & HR
Retail
Sales
Services
Science
Small Business & Entrepreneurship
Food
Environment
Economy & Finance
Data & Analytics
Investor Relations
Sports
Spiritual
News & Politics
Travel
Self Improvement
Real Estate
Entertainment & Humor
Health & Medicine
Devices & Hardware
Lifestyle
Change Language
Language
English
Español
Português
Français
Deutsche
Cancel
Save
EN
Uploaded by
toyship
6,995 views
AVSpeechSynthesizerとロケール
Cookpad Potatotips #1 で発表しました。
Technology
◦
Read more
4
Save
Share
Embed
Embed presentation
Download
Download to read offline
1
/ 11
2
/ 11
3
/ 11
4
/ 11
5
/ 11
6
/ 11
7
/ 11
8
/ 11
9
/ 11
10
/ 11
11
/ 11
More Related Content
PPTX
15分でできるAmazon Alexa Skill開発
by
拓哉 中山
PDF
Downalodable Storyboard
by
Yuta Tokoro
PDF
Bluetooth LEとiBeaconを使った、すれ違い通信
by
幸雄 村上
PDF
アプリのバックグラウンド処理 | iOS 7エンジニア勉強会
by
Yahoo!デベロッパーネットワーク
PDF
Time for Xcode Behavior
by
toyship
PDF
Notifications in iOS10
by
toyship
PDF
Universal Link
by
toyship
PDF
Can we live in a pure Swift world?
by
toyship
15分でできるAmazon Alexa Skill開発
by
拓哉 中山
Downalodable Storyboard
by
Yuta Tokoro
Bluetooth LEとiBeaconを使った、すれ違い通信
by
幸雄 村上
アプリのバックグラウンド処理 | iOS 7エンジニア勉強会
by
Yahoo!デベロッパーネットワーク
Time for Xcode Behavior
by
toyship
Notifications in iOS10
by
toyship
Universal Link
by
toyship
Can we live in a pure Swift world?
by
toyship
More from toyship
PDF
Swift Protocol and Selector
by
toyship
PDF
What's new Swift3
by
toyship
PDF
Xcode7時代のアプリ配布
by
toyship
PDF
My first tvOS
by
toyship
PDF
3D touch for iOS
by
toyship
PDF
Contents blocker on iOS9
by
toyship
PDF
Embedded framework and so on
by
toyship
PDF
はじめてのWKInterfaceController
by
toyship
PDF
App extension for iOS
by
toyship
PDF
サーバーからiOSアプリを変更する
by
toyship
PDF
Xcode bot
by
toyship
Swift Protocol and Selector
by
toyship
What's new Swift3
by
toyship
Xcode7時代のアプリ配布
by
toyship
My first tvOS
by
toyship
3D touch for iOS
by
toyship
Contents blocker on iOS9
by
toyship
Embedded framework and so on
by
toyship
はじめてのWKInterfaceController
by
toyship
App extension for iOS
by
toyship
サーバーからiOSアプリを変更する
by
toyship
Xcode bot
by
toyship
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