/*
*/
package kdxf;
import com.iflytek.cloud.speech.*;
/**
-
@author xr
*/
public class KDXF {private static SynthesizerListener mSystemLister;
private static final String APPID = "*******";/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
String str = "要讀的文字";
String str2 = str.replaceAll(" ", "");
SpeechUtility.createUtility("appid=" + APPID);
//1.創(chuàng)建SpeechSynthesizer對象
SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer();
//2.合成參數設置,詳見《MSC Reference Manual》SpeechSynthesizer 類
mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); //設置發(fā)音人
mTts.setParameter(SpeechConstant.SPEED, "50"); //設置語速 范圍0~100
mTts.setParameter(SpeechConstant.VOLUME, "80"); //設置音量,范圍0~100
//設置合成音頻保存位置(可自定義保存位置),保存在“./tts_test.pcm”
//如果不需要保存合成音頻,注釋該行代碼
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, "./zye.pcm");
//3.開始合成mTts.startSpeaking(str2, new SynthesizerListener() {
//會話結束回調接口,沒有錯誤時,error為null
public void onCompleted(SpeechError error) {
System.out.println(error);
}@Override public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) { } //緩沖進度回調 //percent為緩沖進度0~100,beginPos為緩沖音頻在文本中開始位置,endPos表示緩沖音頻在文本中結束位置,info為附加信息。 public void onBufferProgress(int percent, int beginPos, int endPos, String info) { System.out.println("---"+percent+"----\n"); } //開始播放 public void onSpeakBegin() { } //暫停播放 public void onSpeakPaused() { } //播放進度回調 //percent為播放進度0~100,beginPos為播放音頻在文本中開始位置,endPos表示播放音頻在文本中結束位置. public void onSpeakProgress(int percent, int beginPos, int endPos) { } //恢復播放回調接口 public void onSpeakResumed() { }});
}
-
}