移植原始版本
This commit is contained in:
66
src/main/java/com/yutou/nas/utils/AudioTools.java
Normal file
66
src/main/java/com/yutou/nas/utils/AudioTools.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.iflytek.cloud.speech.*;
|
||||
|
||||
public class AudioTools {
|
||||
private static boolean init = false;
|
||||
|
||||
synchronized static void init() {
|
||||
if (init) {
|
||||
return;
|
||||
}
|
||||
SpeechUtility.createUtility(SpeechConstant.APPID + "=601f7f7d");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.VOLUME,"100");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_64,"/media/yutou/4t/public/servier/tools/");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_32,"/media/yutou/4t/public/servier/tools/");
|
||||
init = true;
|
||||
System.out.println("讯飞语音已初始化");
|
||||
}
|
||||
|
||||
public static void playText(String text) {
|
||||
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
||||
mss.startSpeaking(text, new SynthesizerListener() {
|
||||
@Override
|
||||
public void onBufferProgress(int progress, int beginPos, int endPos,
|
||||
String info) {
|
||||
if (progress == 100) {
|
||||
mss.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakBegin() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakProgress(int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakPaused() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakResumed() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(SpeechError speechError) {
|
||||
System.out.println(speechError.getErrorDesc() + " code " + speechError.getErrorCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
init();
|
||||
playText("小爱同学,开灯");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user