麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

IOS開發(fā)學(xué)習(xí)筆記(一)語音合成

2019-11-14 20:16:05
字體:
供稿:網(wǎng)友

      現(xiàn)在語音服務(wù)越來越熱,我們平時使用的很多軟件都帶有語音合成和識別功能,用起來也很方便。說到語音服務(wù),Google和微軟都提供過API接口,不過筆者要介紹的是國內(nèi)的智能語音技術(shù)提供商---科大訊飛。之前看過一個比較Google、微軟和科大訊飛語音識別引擎的博文(http://fqctyj.blog.163.com/blog/static/70843455201361955322797/),有興趣可以去看看。筆者接觸語音服務(wù)的時間也不長,對語音服務(wù)也不是很了解,但是拆解過科大訊飛的Demo,對語音服務(wù)的程序使用還是知道的。這次只整理了語音合成的代碼,關(guān)于語音識別和其他的下次再發(fā),廢話完了進入正題。

如何實現(xiàn)語音合成呢?

1、注冊訊飛賬號,申請APPID(注意選擇IOS平臺)
2、加載所需要的類庫
3、導(dǎo)入所需要的類庫文件頭
4、調(diào)用申請的APPID以及所需函數(shù),完成語音合成(需要參考官方給出的SDK文件)
 
詳細步驟:

一、首先到科大訊飛官網(wǎng)注冊賬號(http://open.voicecloud.cn/),并創(chuàng)建應(yīng)用獲取appid,下載sdk文件

 

二、代碼實現(xiàn)api調(diào)用

1.先用xcode(我這里使用的是xcode 5.1)新建好一個項目,然后在項目添加要用的類庫。其中有一個是訊飛語音的類庫iflyMSC,在下載的sdk文件里有,導(dǎo)入就行了。導(dǎo)入的時候要注意把iflyMSC類庫拷貝到你的工程目錄里,不然后果很嚴重!

 

2.導(dǎo)完類庫之后,在建好的工程里添加好要用的頭文件。

MainViewController.h

1 #import <UIKit/UIKit.h>2 #import "iflyMSC/IFlySpeechSynthesizerDelegate.h"

MainViewController.m

1 #import "MainViewController.h"2 #import <QuartzCore/QuartzCore.h>3 #import <AVFoundation/AVAudiosession.h>4 #import <AudioToolbox/AudioSession.h>5 #import "iflyMSC/IFlySpeechConstant.h"6 #import "iflyMSC/IFlySpeechUtility.h"7 #import "iflyMSC/IFlySpeechSynthesizer.h"

3.完成這些準(zhǔn)備工作之后,接下來就是堆代碼的工作了。為了方便,筆者只用了兩個控件:一個UITextField、一個UIButton,然后給這兩個控件分別做一個Outlet和Action連接。

MainViewController.h

 1 #import <UIKit/UIKit.h> 2 #import "iflyMSC/IFlySpeechSynthesizerDelegate.h" 3 //引入語音合成類 4 @class IFlySpeechSynthesizer; 5 @class IFlyDataUploader; 6 //注意要添加語音合成代理 7 @interface MainViewController : UIViewController<IFlySpeechSynthesizerDelegate> 8 //聲明語音合成的對象 9 @PRoperty (nonatomic, strong) IFlySpeechSynthesizer *iFlySpeechSynthesizer;10 @property (strong, nonatomic) IBOutlet UITextField *content;11 12 - (IBAction)Start:(id)sender;13 @end

MainViewController.m

 1 #import "MainViewController.h" 2 #import <QuartzCore/QuartzCore.h> 3 #import <AVFoundation/AVAudioSession.h> 4 #import <AudioToolbox/AudioSession.h> 5 #import "iflyMSC/IFlySpeechConstant.h" 6 #import "iflyMSC/IFlySpeechUtility.h" 7 #import "iflyMSC/IFlySpeechSynthesizer.h" 8  9 @interface MainViewController ()10 11 @end12 13 @implementation MainViewController14 15 - (void)viewDidLoad16 {17     [super viewDidLoad];18     //通過appid連接訊飛語音服務(wù)器,把@"53b5560a"換成你申請的appid19     NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@,timeout=%@",@"53b5560a",@"20000"];20     //所有服務(wù)啟動前,需要確保執(zhí)行createUtility21     [IFlySpeechUtility createUtility:initString];22     23     //創(chuàng)建合成對象,為單例模式24     _iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];25     _iFlySpeechSynthesizer.delegate = self;26 27     //設(shè)置語音合成的參數(shù)28     //合成的語速,取值范圍 0~10029     [_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant SPEED]];30     //合成的音量;取值范圍 0~10031     [_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant VOLUME]];32     //發(fā)音人,默認為”xiaoyan”;可以設(shè)置的參數(shù)列表可參考個性化發(fā)音人列表33     [_iFlySpeechSynthesizer setParameter:@"xiaoyan" forKey:[IFlySpeechConstant VOICE_NAME]];34     //音頻采樣率,目前支持的采樣率有 16000 和 800035     [_iFlySpeechSynthesizer setParameter:@"8000" forKey:[IFlySpeechConstant SAMPLE_RATE]];36     ////asr_audio_path保存錄音文件路徑,如不再需要,設(shè)置value為nil表示取消,默認目錄是documents37     [_iFlySpeechSynthesizer setParameter:"tts.pcm" forKey:[IFlySpeechConstant TTS_AUDIO_PATH]];38 39     //隱藏鍵盤,點擊空白處40     UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];41     tapGr.cancelsTouchesInView = NO;42     [self.view addGestureRecognizer:tapGr];  43 }44 45 -(void)viewTapped:(UITapGestureRecognizer*)tapGr46 {47     [self.content resignFirstResponder];48 }49 50 - (void)didReceiveMemoryWarning51 {52     [super didReceiveMemoryWarning];53     // Dispose of any resources that can be recreated.54 }55 56 - (IBAction)Start:(id)sender 57 {58     //啟動合成會話59     [_iFlySpeechSynthesizer startSpeaking:self.content.text];60 }61 62 #pragma mark - IFlySpeechSynthesizerDelegate63 //開始播放64 - (void) onSpeakBegin65 {66     67 }68 69 //緩沖進度70 - (void) onBufferProgress:(int) progress message:(NSString *)msg71 {72     NSLog(@"bufferProgress:%d,message:%@",progress,msg);73 }74 75 //播放進度76 - (void) onSpeakProgress:(int) progress77 {78     NSLog(@"play progress:%d",progress);79 }80 81  //暫停播放82 - (void) onSpeakPaused83 {84     85 }86 87 //恢復(fù)播放88 - (void) onSpeakResumed89 {90     91 }92 93 //結(jié)束回調(diào)94 - (void) onCompleted:(IFlySpeechError *) error95 {96     97 }98 @end

4.以上的代理方法其實是可以不寫的,但是官方給出的說明是需要加上的。若是在運行過程中出現(xiàn)錯誤,可以查看開發(fā)者文檔的錯誤碼列表,找出相應(yīng)的錯誤。如果大家對以上的講解還有不懂的地方,請仔細閱讀官方提供的sdk文件,里面有詳細的說明,也可以給我留言。

PS:若本文有什么錯誤的地方,還望大家指正留言,我會盡快修改!

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人男女啪啪免费观看网站四虎 | 国产高清成人久久 | av手机在线免费播放 | 欧美成人做爰高潮片免费视频 | 精品国产一区二区三区四区阿崩 | 国产精品亚洲欧美 | 亚洲一区二区中文字幕在线观看 | 久久精品成人影院 | 亚洲精品午夜国产va久久成人 | 成人精品aaaa网站 | 欧美一区二区黄 | 曰批全过程120分钟免费69 | 免费午夜网站 | 久久狠狠高潮亚洲精品 | 久久另类视频 | 日本在线高清 | 9丨九色丨国产 | 国产流白浆高潮在线观看 | 欧美激情精品久久久久久黑人 | 国产一区二区三区视频在线观看 | 男人天堂免费 | 99麻豆久久久国产精品免费 | 性少妇videosexfreexx | www.91sese | 毛片免费看网站 | 毛片免费看的 | 欧美在线 | 亚洲 | 精品国产91久久久久久久 | 国产精品自拍99 | 97视频一二区 | 草草视频免费观看 | 成人午夜在线免费视频 | 日本一区二区不卡高清 | 免费男女视频 | 鲁人人人鲁人人鲁精品 | 天天好比网 | 欧美乱淫 | 黄色视屏免费看 | 韩国十九禁高潮床戏在线观看 | 久久综合一区 | 毛片a片 |