Sonido de reconocimiento de voz
Frecuentes
Visto 1,013 veces
0
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.
Aquí está mi código:
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");
}
}
1 Respuestas
0
This should do the trick for you. Add this to your RecognitionListener.onReadyForSpeech()
método.
mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
Respondido el 09 de Septiembre de 13 a las 04:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java android audio android-intent speech-recognition or haz tu propia pregunta.
Has a better solution come along for this? While it "works" to mute the sound, it also mutes the entire stream. It is a bit "hacky" after 4 years. - abandonado la Cesta