日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

初识--AVSpeechSynthesizer

發布時間:2025/4/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 初识--AVSpeechSynthesizer 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

什么是AVSpeechSynchronizer?

從IOS5開始,IOS系統已經在siri上集成了語音合成的功能,但是是私有API。但是在IOS7,新增了一個簡單的API----AVSpeechSynthesizer來做這件事情。目前比較主流的語音識別和合成的工具“科大訊飛”很強大,使用起來也很簡單,當然如果是簡單的“文本到語音”的功能,在iOS中已經提供好了相關的API,開發者可以使用AV Foundation中的AVSpeechSynthesizer類來實現這個功能。

那我就直接上代碼嘍:

#import "ViewController.h" #import <AVFoundation/AVFoundation.h>@interface ViewController ()<AVSpeechSynthesizerDelegate>//AVSpeechSynthesizer代理//聲明AVSpeechSynthesizer屬性 @property (nonatomic, strong) AVSpeechSynthesizer *synthesizer;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.//創建一個AVSpeechSynthesizer對象self.synthesizer = [[AVSpeechSynthesizer alloc]init];//設置代理人為當前控制器對象self.synthesizer.delegate = self;//創建AVSpeechUtterance對象(播放的語音內容都是通過實例化AVSpeechUtterance而得到)AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:@"你好,就是愛你愛著你,你能把我咋地"];// 語速 0.0f~1.0futterance.rate = 0.5f;// 聲音的音調 0.5f~2.0futterance.pitchMultiplier = 0.8f;// 使播放下一句的時候有0.1秒的延遲utterance.postUtteranceDelay = 0.1f;//系統默認是不支持中文的(下面是設置中文)utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];//國家語言//播放 [_synthesizer speakUtterance:utterance]; } //AVSpeechSynthesizer的代理方法 -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{NSLog(@"開始播放"); } -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance{NSLog(@"暫停播放"); } -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance{NSLog(@"結束播放"); } -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance{NSLog(@"退出播放狀態"); } -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance{NSLog(@"跳出播放狀態"); } -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance{NSLog(@"播放狀態時,當前所播放的字符串范圍,及AVSpeechUtterance實例(可通過此方法監聽當前播放的字或者詞"); }@end

?

轉載于:https://www.cnblogs.com/LzwBlog/p/5688641.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的初识--AVSpeechSynthesizer的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。