开放能力
开发平台
行业应用
生态合作
开发与教学
资讯 社区 控制台
技术能力
语音技术
图像技术
文字识别
人脸与人体识别
视频技术
AR与VR
自然语言处理
知识图谱
数据智能
场景方案
部署方案
行业应用
智能教育
智能医疗
智能零售
智能工业
企业服务
智能政务
智能农业
信息服务
智能园区
智能硬件
语音技术

    完整示例

    完整示例

    语音合成完整示例

       
    -(void)configureOnlineTTS{
        
        [[BDSSpeechSynthesizer sharedInstance] setApiKey:API_KEY withSecretKey:SECRET_KEY];
        
        [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];
        [[BDSSpeechSynthesizer sharedInstance] setSynthParam:@(BDS_SYNTHESIZER_SPEAKER_FEMALE) forKey:BDS_SYNTHESIZER_PARAM_SPEAKER];
        
    }
    
    -(void)configureOfflineTTS{
        
        NSError *err = nil;
        // 在这里选择不同的离线音库(请在XCode中Add相应的资源文件),同一时间只能load一个离线音库。根据网络状况和配置,SDK可能会自动切换到离线合成。
        NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Speech_Female" ofType:@"dat"];
        
        NSString* offlineChineseAndEnglishTextData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Text" ofType:@"dat"];
        
        err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineChineseAndEnglishTextData speechDataPath:offlineEngineSpeechData licenseFilePath:nil withAppCode:APP_ID];
        if(err){
            [self displayError:err withTitle:@"Offline TTS init failed"];
            return;
        }
        [TTSConfigViewController loadedAudioModelWithName:@"Chinese female" forLanguage:@"chn"];
        [TTSConfigViewController loadedAudioModelWithName:@"English female" forLanguage:@"eng"];
    }
    
    -(void)test : {
        	// 获得合成器实例
        [[BDSSpeechSynthesizer sharedInstance] setSynthesizerDelegate:self];
    	
    	// 设置委托对象
    	[[BDSSpeechSynthesizer sharedInstance] setSynthesizerDelegate:self];
    	
    	// 开始合成并播放
    	NSError* speakError = nil;
    	if([[BDSSpeechSynthesizer sharedInstance] speakSentence:@"您好" withError:&speakError] == -1){
    		// 错误
    		NSLog("错误: %ld, %@", (long)speakError.code, speakError.localizedDescription);
    	}
    	if([[BDSSpeechSynthesizer sharedInstance] speakSentence:@"今天天气真不错" withError:&speakError] == -1){
    		// 错误
    		NSLog("错误: %ld, %@", (long)speakError.code, speakError.localizedDescription);
    	}
    	if([[BDSSpeechSynthesizer sharedInstance] speakSentence:@"Today's weather is really good!" withError:&speakError] == -1){
    		// 错误
    		NSLog("错误: %ld, %@", (long)speakError.code, speakError.localizedDescription);
    	}
    }
    	
    	
    	- (void)synthesizerStartWorkingSentence:(NSInteger)SynthesizeSentence
    {
        NSLog(@"Began synthesizing sentence %ld", (long)SynthesizeSentence);
    }
    
    - (void)synthesizerFinishWorkingSentence:(NSInteger)SynthesizeSentence
    {
        NSLog(@"Finished synthesizing sentence %ld", (long)SynthesizeSentence);
    }
    
    - (void)synthesizerSpeechStartSentence:(NSInteger)SpeakSentence
    {
        NSLog(@"Began playing sentence %ld", (long)SpeakSentence);
    }
    
    - (void)synthesizerSpeechEndSentence:(NSInteger)SpeakSentence
    {
        NSLog(@"Finished playing sentence %ld", (long)SpeakSentence);
    }
    上一篇
    参数和错误说明
    下一篇
    常见问题