问题描述
我现在用的是语音识别意图把用户输入,并将其转换为文本。不过,我想的意图,不断采取用户输入,并把它翻译成文字,看看用户说某个词。我的code是能够做到这一点,但每次我的应用程序开始监听输入时间,手机做一个短的蜂鸣声,它已准备好投入。
我想知道是否有任何方式从每打识别器已准备好再次听一次删除的声音。
下面是我的code:
进口的java.util.ArrayList;进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.speech.RecognitionListener;
进口android.speech.RecognizerIntent;
进口android.speech.SpeechRecognizer;
进口android.util.Log;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Toast;
进口android.widget.ToggleButton;
公共类MainActivity扩展活动实现OnClickListener
{ //私人TextView的多行文字;
私人SpeechRecognizer SR;
私有静态最后弦乐TAG =MyStt3Activity;
@覆盖
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
切换按钮speakButton =(切换按钮)findViewById(R.id.CarMode);
//多行文字=(的TextView)findViewById(R.id.textView1);
speakButton.setOnClickListener(本);
SR = SpeechRecognizer.createSpeechRecognizer(本);
sr.setRecognitionListener(新监听器());
} 监听器类实现RecognitionListener
{
公共无效onReadyForSpeech(捆绑PARAMS)
{
Log.d(TAGonReadyForSpeech);
}
公共无效onBeginningOfSpeech()
{
Log.d(TAGonBeginningOfSpeech);
}
公共无效onRmsChanged(浮动rmsdB)
{
Log.d(TAGonRmsChanged);
}
公共无效onBufferReceived(字节[]缓冲区)
{
Log.d(TAGonBufferReceived);
}
公共无效onEndOfSpeech()
{
Log.d(TAGonEndofSpeech);
}
公共无效onerror的(INT错误)
{
Log.d(TAG,错误+误差);
Toast.makeText(getApplicationContext(),那是什么?,Toast.LENGTH_SHORT).show();
sr.cancel();
speechIntent();
}
公共无效onResults(捆绑结果)
{
//字符串str =新的String();
Log.d(TAGonResults+结果);
ArrayList的<串GT;数据= results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Toast.makeText(getApplicationContext(),data.get(0),Toast.LENGTH_SHORT).show();
sr.cancel();
speechIntent();
//mText.setText(\"results:+将String.valueOf(data.size()));
}
公共无效onPartialResults(捆绑partialResults)
{
Log.d(TAGonPartialResults);
}
公共无效的onEvent(INT EVENTTYPE,捆绑PARAMS)
{
Log.d(TAG的onEvent+ EVENTTYPE);
}
}
公共无效的onClick(视图v){
如果(v.getId()== R.id.CarMode)
{
speechIntent();
}
} 公共无效speechIntent()
{
意向意图=新意图(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGEcom.example.freestyleandroid); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
sr.startListening(意向);
Log.i(111111,11111111);
}
}
这应该为你做的伎俩。添加到您的 RecognitionListener.onReadyForSpeech()
方法。
mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM,FALSE);
I am using the Speech Recognizer Intent to take User Input and translate it into text. However I want the Intent to continuously take user input and translate it into text to see if the user and said a certain word. My Code is able to do that, but every time my app begins listening for input, the phone makes a short beep sound that it is ready for input.
I was wondering if there is any way to delete the sound from playing every time the recognizer is ready to listen again.
Here is my code:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends Activity implements OnClickListener
{
//private TextView mText;
private SpeechRecognizer sr;
private static final String TAG = "MyStt3Activity";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ToggleButton speakButton = (ToggleButton) findViewById(R.id.CarMode);
//mText = (TextView) findViewById(R.id.textView1);
speakButton.setOnClickListener(this);
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
}
class listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params)
{
Log.d(TAG, "onReadyForSpeech");
}
public void onBeginningOfSpeech()
{
Log.d(TAG, "onBeginningOfSpeech");
}
public void onRmsChanged(float rmsdB)
{
Log.d(TAG, "onRmsChanged");
}
public void onBufferReceived(byte[] buffer)
{
Log.d(TAG, "onBufferReceived");
}
public void onEndOfSpeech()
{
Log.d(TAG, "onEndofSpeech");
}
public void onError(int error)
{
Log.d(TAG, "error " + error);
Toast.makeText(getApplicationContext(), "What was that?", Toast.LENGTH_SHORT).show();
sr.cancel();
speechIntent();
}
public void onResults(Bundle results)
{
//String str = new String();
Log.d(TAG, "onResults " + results);
ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Toast.makeText(getApplicationContext(), data.get(0), Toast.LENGTH_SHORT).show();
sr.cancel();
speechIntent();
//mText.setText("results: "+String.valueOf(data.size()));
}
public void onPartialResults(Bundle partialResults)
{
Log.d(TAG, "onPartialResults");
}
public void onEvent(int eventType, Bundle params)
{
Log.d(TAG, "onEvent " + eventType);
}
}
public void onClick(View v) {
if (v.getId() == R.id.CarMode)
{
speechIntent();
}
}
public void speechIntent()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"com.example.freestyleandroid");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
sr.startListening(intent);
Log.i("111111","11111111");
}
}
This should do the trick for you. Add this to your RecognitionListener.onReadyForSpeech()
method.
mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
这篇关于语音识别声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!