科大訊飛SDK学習と総括
10892 ワード
科大訊飛SDK使用研究音声リスニング(主要オブジェクトSpeechRecognizer) 初期化 設定パラメータ 傍受開始 傍受処理 外部オーディオファイル を認識する.音声合成(プライマリオブジェクトSpeechSynthesizer) 初期化 設定パラメータ 合成開始 傍受処理 音声起動(メインオブジェクトVoiceWakeuper) 初期化 設定パラメータ 起動起動起動 傍受処理
SpeechRecognizer recognizer=SpeechRecognizer.createRecognizer(activity,initListener);
/**
* , :
* 1. SpeechConstant.ENGINE_TYPE , TYPE_LOCAL,TYPE_CLOUD
* 2. SpeechConstant.RESULT_TYPE, “json”
* 3. SpeechConstant.LANGUAGE , , “zh_cn”,"en_us"
* 4. , SpeechConstant.VAD_BOS ,
* 5. , SpeechConstant.VAD_EOS,
* 6. SpeechConstant.ASR_PTT , ‘0’,‘1’
* 7. SpeechConstant.AUDIO_FORMAT , “pcm”,"wav"
* 8. SpeechConstant.ASR_AUDIO_PATH ,
*/
recognizer.setParameter(paramKey,paramValue);
recognizer.startListening(recognizerListener);
recognizerListener = new RecognizerListener() {
@Override
public void onBeginOfSpeech() {
// :sdk ,
}
@Override
public void onError(SpeechError error) {
// Tips:
// :10118( ), , 。
}
@Override
public void onEndOfSpeech() {
// : , ,
}
@Override
public void onResult(RecognizerResult results, boolean isLast) {
// RecognizerResult ,
}
@Override
public void onVolumeChanged(int volume, byte[] data) {
//
}
@Override
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
// id, id , ,
// , id null
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
// Log.d(TAG, "session id =" + sid);
// }
}
};
// SpeechConstant.AUDIO_SOURCE , “-1”,“-2”
// , recognizer
recognizer.writeAudio(audioData, 0, audioData.length);
SpeechSynthesizer synthesizer=SpeechSynthesizer.createSynthesizer(activity, initListener);
/**
* , :
* 1. SpeechConstant.ENGINE_TYPE , TYPE_LOCAL,TYPE_CLOUD
* 2. SpeechConstant.VOICE_NAME,
* 3. SpeechConstant.SPEED ,
* 4. SpeechConstant.PITCH ,
* 5. SpeechConstant.VOLUME,
* 6. SpeechConstant.STREAM_TYPE ,
* 7. SpeechConstant.AUDIO_FORMAT , “pcm”,"wav"
* 8. SpeechConstant.ASR_AUDIO_PATH ,
*/
synthesizer.setParameter(paramKey,paramValue);
synthesizer.startSpeaking(string, synthesizerListener);
synthesizerListener = new SynthesizerListener() {
@Override
public void onSpeakBegin() {
//
}
@Override
public void onSpeakPaused() {
//
}
@Override
public void onSpeakResumed() {
//
}
@Override
public void onBufferProgress(int percent, int beginPos, int endPos,
String info) {
//
}
@Override
public void onSpeakProgress(int percent, int beginPos, int endPos) {
//
}
@Override
public void onCompleted(SpeechError error) {
//
}
@Override
public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
// id, id , ,
// , id null
// if (SpeechEvent.EVENT_SESSION_ID == eventType) {
// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
// Log.d(TAG, "session id =" + sid);
// }
}
};
VoiceWakeuper wakeuper=VoiceWakeuper.createWakeuper(activity, initListener);
/**
* , :
* 1. SpeechConstant.IVW_RES_PATH ,
* 2. SpeechConstant.IVW_SST, ‘wakeup’,‘oneshot’
* 3. SpeechConstant.IVW_THRESHOLD ,
* 4. SpeechConstant.KEEP_ALIVE , ‘0’,‘1’
* 5. SpeechConstant.IVW_NET_MODE, ‘0’,‘1’
* 6. SpeechConstant.AUDIO_FORMAT , “pcm”,"wav"
* 7. SpeechConstant.ASR_AUDIO_PATH ,
*/
wakeuper.setParameter(paramKey,paramValue);
wakeuper.startListening(wakeuperListener);
wakeuperListener = new WakeuperListener() {
@Override
public void onResult(WakeuperResult result) {
//
}
@Override
public void onError(SpeechError error) {
//
}
@Override
public void onBeginOfSpeech() {
//
}
@Override
public void onEvent(int eventType, int isLast, int arg2, Bundle obj) {
switch( eventType ){
// EVENT_RECORD_DATA NOTIFY_RECORD_DATA
case SpeechEvent.EVENT_RECORD_DATA:
final byte[] audio = obj.getByteArray( SpeechEvent.KEY_EVENT_RECORD_DATA );
Log.i( TAG, "ivw audio length: "+audio.length );
break;
}
}
@Override
public void onVolumeChanged(int volume) {
}
};
未完待续..