我是靠谱客的博主 虚拟盼望,最近开发中收集的这篇文章主要介绍ios集成语音朗读功能使用AVSpeechSynthesizer朗读文字,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述


使用AVSpeechSynthesizer朗读文字

所有的嗓音如下:


"[AVSpeechSynthesisVoice 0x978a0b0] Language: th-TH", 
"[AVSpeechSynthesisVoice 0x977a450] Language: pt-BR", 
"[AVSpeechSynthesisVoice 0x977a480] Language: sk-SK",
"[AVSpeechSynthesisVoice 0x978ad50] Language: fr-CA", 
"[AVSpeechSynthesisVoice 0x978ada0] Language: ro-RO", 
"[AVSpeechSynthesisVoice 0x97823f0] Language: no-NO",
"[AVSpeechSynthesisVoice 0x978e7b0] Language: fi-FI", 
"[AVSpeechSynthesisVoice 0x978af50] Language: pl-PL", 
"[AVSpeechSynthesisVoice 0x978afa0] Language: de-DE", 
"[AVSpeechSynthesisVoice 0x978e390] Language: nl-NL", 
"[AVSpeechSynthesisVoice 0x978b030] Language: id-ID", 
"[AVSpeechSynthesisVoice 0x978b080] Language: tr-TR", 
"[AVSpeechSynthesisVoice 0x978b0d0] Language: it-IT", 
"[AVSpeechSynthesisVoice 0x978b120] Language: pt-PT",
"[AVSpeechSynthesisVoice 0x978b170] Language: fr-FR",
"[AVSpeechSynthesisVoice 0x978b1c0] Language: ru-RU", 
"[AVSpeechSynthesisVoice 0x978b210] Language: es-MX", 
"[AVSpeechSynthesisVoice 0x978b2d0] Language: zh-HK",  中文(香港) 粤语
"[AVSpeechSynthesisVoice 0x978b320] Language: sv-SE", 
"[AVSpeechSynthesisVoice 0x978b010] Language: hu-HU",
"[AVSpeechSynthesisVoice 0x978b440] Language: zh-TW",  中文(台湾)
"[AVSpeechSynthesisVoice 0x978b490] Language: es-ES",
"[AVSpeechSynthesisVoice 0x978b4e0] Language: zh-CN",  中文(普通话)
"[AVSpeechSynthesisVoice 0x978b530] Language: nl-BE", 
"[AVSpeechSynthesisVoice 0x978b580] Language: en-GB",  英语(英国)
"[AVSpeechSynthesisVoice 0x978b5d0] Language: ar-SA", 
"[AVSpeechSynthesisVoice 0x978b620] Language: ko-KR",
"[AVSpeechSynthesisVoice 0x978b670] Language: cs-CZ",
"[AVSpeechSynthesisVoice 0x978b6c0] Language: en-ZA", 
"[AVSpeechSynthesisVoice 0x978aed0] Language: en-AU",
"[AVSpeechSynthesisVoice 0x978af20] Language: da-DK",
"[AVSpeechSynthesisVoice 0x978b810] Language: en-US",  英语(美国)
"[AVSpeechSynthesisVoice 0x978b860] Language: en-IE",
"[AVSpeechSynthesisVoice 0x978b8b0] Language: hi-IN", 
"[AVSpeechSynthesisVoice 0x978b900] Language: el-GR",
"[AVSpeechSynthesisVoice 0x978b950] Language: ja-JP" )

上代码:

#import <AVFoundation/AVFoundation.h>
    
// 创建嗓音,指定嗓音不存在则返回nil
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
    
// 创建语音合成器
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    
// 实例化发声的<a target=_blank href="http://www.codes51.com/article/search_%e5%af%b9%e8%b1%a1/" target="_blank"><strong>对象</strong></a>
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"跑步完成"];
utterance.voice = voice;
utterance.rate = 0.5;<span style="white-space:pre">	</span>// 语速
    
// 朗读的内容
[synthesizer speakUtterance:utterance];

如果提示这种错误:
|AXSpeechAssetDownloader|error| ASAssetQuery error fetching results (for com.apple.MobileAsset.MacinTalkVoiceAssets) Error Domain=ASError Code=21 "Unable to copy asset information" UserInfo={NSDescription=Unable to copy asset information}
请去iPhone里设置:

进入iPhone的 设置 > 通用 > 辅助功能 > 语音,开启“朗读所选项”,并在“嗓音”中选择“中文(台湾)”

最后

以上就是虚拟盼望为你收集整理的ios集成语音朗读功能使用AVSpeechSynthesizer朗读文字的全部内容,希望文章能够帮你解决ios集成语音朗读功能使用AVSpeechSynthesizer朗读文字所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部