標籤:
1.進入官網註冊帳號,登陸,註冊,應用。
2,下載sdk 匯入系統庫。
3,關閉bitcode
4,初始化訊飛語音。
NSString * initString = [[NSString alloc] initWithFormat:@"appid=%@",@"56fb34f4"];
[IFlySpeechUtility createUtility:initString];
5.整合代碼
#import <UIKit/UIKit.h>
#import "iflyMSC/IFlySpeechConstant.h"
#import "iflyMSC/IFlySpeechSynthesizer.h"
#import "iflyMSC/IFlySpeechSynthesizerDelegate.h"
@interface ViewController : UIViewController<IFlySpeechSynthesizerDelegate>
{
IFlySpeechSynthesizer * _iFlySpeechSynthesizer;
}
@end
#import "ViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.textField.delegate = self;
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance]; _iFlySpeechSynthesizer.delegate =
self;
//2.設定合成參數
//設定線上工作方式
[_iFlySpeechSynthesizer setParameter:[IFlySpeechConstant TYPE_CLOUD]
forKey:[IFlySpeechConstant ENGINE_TYPE]];
//音量,取值範圍 0~100
[_iFlySpeechSynthesizer setParameter:@"50" forKey: [IFlySpeechConstant VOLUME]];
//發音人,預設為”xiaoyan”,可以設定的參數列表可參考“合成發音人列表” [_iFlySpeechSynthesizer setParameter:@" xiaoyan " forKey: [IFlySpeechConstant VOICE_NAME]]; //儲存合成檔案名稱,如不再需要,設定設定為nil或者為空白表示取消,預設目錄位於 library/cache下
[_iFlySpeechSynthesizer setParameter:@" tts.pcm" forKey: [IFlySpeechConstant TTS_AUDIO_PATH]];
[_iFlySpeechSynthesizer setParameter:@"" forKey:[IFlySpeechConstant VOICE_NAME]];
NSString * str = [IFlySpeechConstant VOICE_NAME];
NSLog(@"%@",str);
}
- (IBAction)voiceAction:(id)sender {
[self.textField resignFirstResponder];
[_iFlySpeechSynthesizer startSpeaking: self.textField.text];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.textField resignFirstResponder];
}
- (IBAction)endVoicePlay:(id)sender {
[_iFlySpeechSynthesizer pauseSpeaking];
}
- (IBAction)resumePlay:(id)sender {
[_iFlySpeechSynthesizer resumeSpeaking];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self voiceAction:nil];
return YES;
}
//結束代理
- (void) onCompleted:(IFlySpeechError *) error{
NSLog(@"結束");
}
//合成開始
- (void) onSpeakBegin{
NSLog(@"合成開始");
}
//合成緩衝進度
- (void) onBufferProgress:(int) progress message:(NSString *)msg
{
}
//合成播放進度
- (void) onSpeakProgress:(int) progress{
}
iOS開發訊飛語音的整合