|
|
@@ -4,34 +4,55 @@ import android.os.Bundle;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
+import com.iflytek.cloud.speech.RecognizerResult;
|
|
|
+import com.iflytek.cloud.speech.SpeechError;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.audio.voicerecognition.JsonParser;
|
|
|
import com.xzjmyk.pm.activity.audio.voicerecognition.VoiceToWord;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
-
|
|
|
+import com.iflytek.cloud.ui.RecognizerDialogListener;
|
|
|
/**
|
|
|
* Created by FANGlh on 2017/1/11.
|
|
|
* function:
|
|
|
*/
|
|
|
-public class SpeechrecognitionActivity extends BaseActivity {
|
|
|
+public class SpeechrecognitionActivity extends BaseActivity implements RecognizerDialogListener{
|
|
|
|
|
|
private EditText identify_words_et;
|
|
|
private Button speak_start_bt;
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.speech_recognition);
|
|
|
+ getSupportActionBar().setTitle("语音识别");
|
|
|
|
|
|
identify_words_et = (EditText) findViewById(R.id.sr_identify_words_et);
|
|
|
speak_start_bt = (Button) findViewById(R.id.sr_speak_start_bt);
|
|
|
-
|
|
|
+ final VoiceToWord voice = new VoiceToWord(SpeechrecognitionActivity.this,"534e3fe2");
|
|
|
+ voice.setRecognizerDialogListener(this); //自己调用自己
|
|
|
speak_start_bt.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- VoiceToWord voice = new VoiceToWord(SpeechrecognitionActivity.this,"534e3fe2");
|
|
|
voice.GetWordFromVoice();
|
|
|
+ identify_words_et.setText("");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResult(RecognizerResult recognizerResult, boolean b) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ String text = JsonParser.parseIatResult(recognizerResult.getResultString());
|
|
|
+ System.out.println(text);
|
|
|
+ Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
|
|
|
+ identify_words_et.setText(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(SpeechError speechError) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|