iOS開發訊飛語音的整合

來源:互聯網
上載者:User

標籤:

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開發訊飛語音的整合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.