Speech to Text on Android

Android Speech to Text Api Google - notification

Android's SpeechRecognizer is only an interface to the speech recognition engine installed in the system and chosen as the default. For example, the default Google's recognizer supports both online and offline modes. When the internet connection is present, it sends raw data to and obtains the final result from the Google's internal cloud recognition service, hence the privacy warning on your screenshot. When there is no internet connection, it uses some proprietary on-board recognizer.

My general advise is to use a speech recognition system that you completely trust to if you are concerned about the privacy of the users' speech input.

How to get past information while converting speech to text in android?

If you only want to save one previously detected String, for this to achieve, you need to make a global String variable and store the value in that variable from results list.(Save the same String as you are setting on text view). But if you want to save all the strings, you need to make global String Arraylist and add all those string in that array list. Below is the code for that.

private EditText txtSpeechInput;
private ImageButton btnSpeak;
private final int REQ_CODE_SPEECH_INPUT = 100;
private List<String> previousStringList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

previousStringList = new ArrayList<>();

txtSpeechInput = findViewById(R.id.txtSpeechInput);
btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
promptSpeechInput();
}
});
}

private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 20000000);

try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {

final ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

txtSpeechInput.setText(result.get(0));
if (result.get(0) != null) {
previousStringList.add(result.get(0));
}
}
break;
}

}
}

Hope that helps you.If you don't understand anything feel free to ask. If you don't want to save same String twice(already saved string), just replace below conditional line of code..

if (result.get(0) != null && !previousStringList.contains(result.get(0))) {
previousStringList.add(result.get(0));
}

Long audio speech recognition on Android

I have successfully accomplished this with the help of Google Cloud Speech API. They have also added a demo here.

Google Cloud Speech-to-Text enables developers to convert audio to text by applying powerful neural network models in an easy to use API. The API recognizes 120 languages and variants, to support your global user base. You can enable voice command-and-control, transcribe audio from call centers, and more. It can process real-time streaming or pre-recorded audio, using Google’s machine learning technology.

You can transcribe the text of users dictating to an application’s microphone, enable command-and-control through voice, or
transcribe audio files, among many other use cases. Recognize audio
uploaded in the request, and integrate with your audio storage on
Google Cloud Storage, by using the same technology Google uses to
power its own products.

Android speech to text :: getting text updated at realtime

You can't achieve a realtime recognition with google API. In the best case you can achieve the same result than google when you are using OK Google or for example Recognition in Whatsup for write Text word by word adding to your intent:

recognizerIntent.putExtra("android.speech.extra.DICTATION_MODE", true);

The Speechrecognizer take his time to process all the info and split it as info to be able to use it in your app. you can check the next post to see if it help you optimizing your app: Make SpeechRecognizer Faster

Hope that it will help you !

speech recognizer set text in edit text mishap (Android studio)

@Override
public void onResults(Bundle results) {
micButton.setImageResource(R.drawable.ic_baseline_mic_off_24);
ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
editTextDescription.setSelection(editTextDescription.getText().length());
editTextDescription.setText(data.get(0));
}

You're telling it to hilight the entire text, then you set the text. That's going to get rid of whatever the selection is (it's also redundant, as the same thing would happen if you didn't set the selection). If you want to continue it, use

editTextDescription.setText(editTextDescription.getText().toString()+data.get(0))

That should replace the last 2 lines of that function. It will get the existing text, tack the new result to it, and set the total string to the view.



Related Topics



Leave a reply



Submit