语音识别中的果冻豆蜂鸣声

语音识别中的果冻豆蜂鸣声,第1张

概述我一直在研究不同的线程,但是没有发现任何对我遇到的问题有用的东西.我想摆脱语音识别开始时发出的“哔”声.我正在使用JellyBean4.2.2,因此不确定在早期版本中是否存在相同的问题,如果我也想解决此问题.另外,我想知道是否有人对如何响应某些语音识别结果提出建议.请让我知道我的

我一直在研究不同的线程,但是没有发现任何对我遇到的问题有用的东西.我想摆脱语音识别开始时发出的“哔”声.我正在使用Jelly Bean 4.2.2,因此不确定在早期版本中是否存在相同的问题,如果我也想解决此问题.另外,我想知道是否有人对如何响应某些语音识别结果提出建议.请让我知道我的代码如何即兴包含这些功能.

package com.example.speech;import java.util.ArrayList;import androID.media.AudioManager;import androID.os.Build;import androID.os.Bundle;import androID.os.CountDownTimer;import androID.app.Activity;import androID.content.Intent;import androID.speech.RecognitionListener;import androID.speech.RecognizerIntent;import androID.speech.SpeechRecognizer;import androID.vIEw.Menu;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.VIEw;import androID.Widget.ArrayAdapter;import androID.Widget.button;import androID.Widget.ListVIEw;import androID.util.Log;public class MainActivity extends Activity implements  OnClickListener {ListVIEw lv;private SpeechRecognizer mSpeechRecognizer;private Intent mSpeechRecognizerIntent; boolean reseter = false;private AudioManager mAudioManager;private volatile boolean mNoSpeechCountDownOn;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    boolean available = SpeechRecognizer.isRecognitionAvailable(this);    Log.d("Speech", "available = " + available);    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);    mSpeechRecognizer.setRecognitionListener(new SpeechListener());    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALliNG_PACKAGE,            this.getPackagename());    mAudioManager = (AudioManager) getSystemService(this.AUdio_SERVICE);    commandA();}private CountDownTimer mNoSpeechCountDown = new CountDownTimer(5000, 5000){       @OverrIDe    public voID onTick(long millisUntilFinished)    {    }    @SuppressWarnings("synthetic-access")    @OverrIDe    public voID onFinish()    {        mNoSpeechCountDownOn = false;        mSpeechRecognizer.cancel();        mSpeechRecognizer.startListening(mSpeechRecognizerIntent);    }};@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.main, menu);    return true;}private class SpeechListener implements RecognitionListener {    @OverrIDe    public voID onBeginningOfSpeech() {        if (mNoSpeechCountDownOn)        {            mNoSpeechCountDownOn = false;            mNoSpeechCountDown.cancel();        }        Log.d("Speech", "onBeginningOfSpeech");    }    @OverrIDe    public voID onBufferReceived(byte[] buffer) {        Log.d("Speech", "onBufferReceived");    }    @OverrIDe    public voID onEndOfSpeech() {        Log.d("Speech", "onEndOfSpeech");    }    @OverrIDe    public voID one rror(int error) {        if (mNoSpeechCountDownOn)        {            mNoSpeechCountDownOn = false;            mNoSpeechCountDown.cancel();        }        Log.d("Speech", "onError");    }    @OverrIDe    public voID onEvent(int eventType, Bundle params) {        Log.d("Speech", "onEvent");    }    @OverrIDe    public voID onPartialResults(Bundle partialResults) {        Log.d("Speech", "onPartialResults");    }    @OverrIDe    public voID onReadyForSpeech(Bundle params) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)        {            mNoSpeechCountDownOn = true;            mNoSpeechCountDown.start();            mAudioManager.setStreamMute(AudioManager.STREAM_SYstem, false);        }        Log.d("Speech", "onReadyForSpeech");        try {            Thread.sleep(4900);        } catch (InterruptedException e) {            mSpeechRecognizer.startListening(mSpeechRecognizerIntent);            mAudioManager.setStreamMute(AudioManager.STREAM_SYstem, true);            Log.d("speech", "Mute on");        }    }    @OverrIDe    public voID onResults(Bundle results) {        Log.d("Speech", "results");        ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESulTS_RECOGNITION);        // Do whatever you want here        try {            Thread.sleep(1);        } catch (InterruptedException e) {            mSpeechRecognizer.startListening(mSpeechRecognizerIntent);            mAudioManager.setStreamMute(AudioManager.STREAM_SYstem, true);            Log.d("speech", "Mute on");        }    }    @OverrIDe    public voID onRmsChanged(float rmsdB) {        //Log.d("Speech", "onRmsChanged");    }}@OverrIDepublic voID onClick(VIEw v) {    // Todo auto-generated method stub} }

解决方法:

public class MainActivity extends Activity implements OnClickListener {ListVIEw lv;private SpeechRecognizer mSpeechRecognizer;private Intent mSpeechRecognizerIntent; boolean reseter = false;private AudioManager mAudioManager;OverrIDeprotected voID onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentVIEw(R.layout.activity_main);lv = (ListVIEw)findVIEwByID(R.ID.lvVoiceReturn);button b= (button)findVIEwByID(R.ID.bVoice);b.setonClickListener(this);boolean available = SpeechRecognizer.isRecognitionAvailable(this);Log.d("Speech", "available = " + available);mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);mSpeechRecognizer.setRecognitionListener(new SpeechListener());mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALliNG_PACKAGE,        this.getPackagename());mAudioManager = (AudioManager) getSystemService(Context.AUdio_SERVICE);}private CountDownTimer mNoSpeechCountDown = new CountDownTimer(5000, 5000){       @OverrIDe    public voID onTick(long millisUntilFinished)    {    }    @SuppressWarnings("synthetic-access")    @OverrIDe    public voID onFinish()    {        mNoSpeechCountDownOn = false;        mSpeechRecognizer.cancel();        mSpeechRecognizer.startListening(mSpeechRecognizerIntent);    }};@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@OverrIDepublic voID onClick(VIEw v) { // Todo auto-generated method stub`Log.d("speech", "button active");mSpeechRecognizer.startListening(mSpeechRecognizerIntent);mAudioManager.setStreamMute(AudioManager.STREAM_SYstem, true);}private class SpeechListener implements RecognitionListener {@OverrIDepublic voID onBeginningOfSpeech() {    if (mNoSpeechCountDownOn)    {                mNoSpeechCountDownOn = false;                mNoSpeechCountDown.cancel();    }    Log.d("Speech", "onBeginningOfSpeech");}@OverrIDepublic voID onBufferReceived(byte[] buffer) {    Log.d("Speech", "onBufferReceived");}@OverrIDepublic voID onEndOfSpeech() {    Log.d("Speech", "onEndOfSpeech");}@OverrIDepublic voID one rror(int error) {    if (mNoSpeechCountDownOn)    {                mNoSpeechCountDownOn = false;                mNoSpeechCountDown.cancel();    }    Log.d("Speech", "onError");}@OverrIDepublic voID onEvent(int eventType, Bundle params) {    Log.d("Speech", "onEvent");}@OverrIDepublic voID onPartialResults(Bundle partialResults) {    Log.d("Speech", "onPartialResults");}@OverrIDepublic voID onReadyForSpeech(Bundle params) {    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)    {                mNoSpeechCountDownOn = true;                mNoSpeechCountDown.start();          mAudioManager.setStreamMute(AudioManager.STREAM_SYstem, false);    }    Log.d("Speech", "onReadyForSpeech");}@OverrIDepublic voID onResults(Bundle results) {    Log.d("Speech", "results");    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESulTS_RECOGNITION);  // Do whatever you want here}@OverrIDepublic voID onRmsChanged(float rmsdB) {    //Log.d("Speech", "onRmsChanged");}}}

总结

以上是内存溢出为你收集整理的语音识别中的果冻豆蜂鸣声全部内容,希望文章能够帮你解决语音识别中的果冻豆蜂鸣声所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1074998.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存