iOS语音合成

iOS语音合成,第1张

概述添加引用 1 import AVFoundation 播放语音 1 2 3 4 5 6 7 8 9 let player = AVSpeechSynthesizer(); player.delegate = self; let u = AVSpeechUtterance(string: "今天天气不错"); u.voice = AVSpeechSynthesisVoice(language: "z 添加引用
1
import AVFoundation
播放语音
1
2
3
4
5
6
7
8
9

let player = AVSpeechSynthesizer();
player.delegate = self;
let u = AVSpeechUtterance(string: "今天天气不错");
u.voice = AVSpeechSynthesisVoice(language: "zh-CN");
u.volume = 1.0;//音量 [0-1] Default = 1
u.rate = 0.48;//播放速度
u.pitchMultiplIEr = 1.0;//播放基准音调 [0.5 - 2] Default = 1
player.speakUtterance(u);

iPhone6以下rate设置为0.1否则会读的很快 iOS的坑啊

代理方法
1
2
3
4
5
6
7
8
9
10
11
12
大专栏  iOS语音合成>13
14
15
//开始播放
func (synthesizer: AVSpeechSynthesizer,dIDStartSpeechUtterance utterance: AVSpeechUtterance) {
print("开始播放")
}

//播放中
func (synthesizer: AVSpeechSynthesizer,willSpeakRangeOfSpeechString characterRange: NSRange,utterance: AVSpeechUtterance) {
let process = Double(characterRange.location) / Double(utterance.speechString.characters.count);
print("播放中,播放进度为:(process)")
}

//播放完毕
func (synthesizer: AVSpeechSynthesizer,dIDFinishSpeechUtterance utterance: AVSpeechUtterance) {
print("播放完毕")
}
常用方法
1
2
3
4
//停止播放
player.stopSpeakingAtBoundary(AVSpeechBoundary.Immediate);
//暂停播放
player.pauseSpeakingAtBoundary(AVSpeechBoundary.Immediate);
总结

以上是内存溢出为你收集整理的iOS语音合成全部内容,希望文章能够帮你解决iOS语音合成所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1018687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存