美文网首页
[iOS功能]- 2019最新:iOS 百度语音合成 离线语音注

[iOS功能]- 2019最新:iOS 百度语音合成 离线语音注

作者: AlwaysLuckyMa | 来源:发表于2019-05-16 17:57 被阅读0次

    配置注意事项 主要针对离线语音合成

    在百度语音开发者平台 如果你不是通过直接创建应用,而是通过应用管理开通语音合成功能,拿到的App ID/API Key/Secret Key name 那么你需要在 应用管理 -> 管理包名 重新设置包名,否则这将影响 离线语音的使用.

    image image

    1.加入系统的framework库

    image image

    重点: 一定要保证拖入的文件夹为黄色, 如果为蓝色是不被编译的

    2.加入头文件 根据自己路径引入头文件

     #import "BDSSpeechSynthesizer.h"
    

    3.加代理

     BDSSpeechSynthesizerDelegate  //百度语音代理
    

    全部代码: 复制粘贴就好 (前提是你的配置文件已经配置好了!)

         [[BDSSpeechSynthesizer sharedInstance] setApiKey:API_KEY withSecretKey:SECRET_KEY];
         [[BDSSpeechSynthesizer sharedInstance] setSynthesizerDelegate:self]; // 设置委托对象
    
         NSError*err =nil;
        // 设置离线引擎
         NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Speech_Female" ofType:@"dat"];
     
         NSString* offlineChineseAndEnglishTextData = [[NSBundlemainBundle]pathForResource:@"Chinese_And_English_Text"ofType:@"dat"];
     
         err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineChineseAndEnglishTextData  speechDataPath:offlineEngineSpeechData licenseFilePath:nil withAppCode:APP_ID];
     
         if(err) {NSLog(@"离线TTS初始化失败 ---  %@", err);}
    
         //选择播音员  0.标准女声 1.普通男声 2.普通男声 3.情感男声 4.情感女声
         [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInt:0] forKey:BDS_SYNTHESIZER_PARAM_SPEAKER];
     
         ///音量 0 ~9
         [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInt:9] forKey:BDS_SYNTHESIZER_PARAM_VOLUME];
        
         ///语速 0 ~9
         [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInt:6] forKey:BDS_SYNTHESIZER_PARAM_SPEED];
        
         ///语调 0 ~9
         [[BDSSpeechSynthesizer sharedInstance] setSynthParam: [NSNumber numberWithInt:6] forKey:BDS_SYNTHESIZER_PARAM_PITCH];
       
         // 开始合成并播放
         NSError* speakError =nil;
         if([[BDSSpeechSynthesizer sharedInstance] speakSentence:speakStr withError:&speakError] == -1){
     
             // 错误
             NSLog(@"错误: %ld, %@", (long)speakError.code, speakError.localizedDescription);
     
         }
    

    相关文章

      网友评论

          本文标题:[iOS功能]- 2019最新:iOS 百度语音合成 离线语音注

          本文链接:https://www.haomeiwen.com/subject/iphwaqtx.html