Marathi - Speech to Text on Android - android

Google Speech-to-Text API supports Marathi as per their documentation here. However I have not been able to get it working on my Android phone. I have already added 'Marathi' in languages for my Android device (Moto G6, running android 7.1.1). However, I am not yet able to get a simple SMS converted from speech-to-text with this. Marathi typing works fine though.
Do I need to modify any other setting? What else is required? Any pointers for this would be highly appreciated.

Have you configured your intent to detect marathi languages as below?
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"mr-IN");
You can checkout other languages codes here.
You can use following code for your reference:
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.RecordBtn:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Use Off line Recognition Engine only...
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, false);
// Use Marathi Speech Recognition Model...
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "mr-IN");
try {
startActivityForResult(intent, SST_REQUEST_CODE);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.error),
Toast.LENGTH_SHORT).show();
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SST_REQUEST_CODE:
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> getResult = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Original.setText(getResult.get(0));
conversionTable = new ConversionTable();
String Transformed_String = conversionTable.transform(getResult.get(0));
result.setText(Transformed_String);
}
break;
}
}

Related

How to implement Xamarin Speech Recognition

I am new in xamarin, and I was wondering if it is possible to implement this kind of speech recognition:
First the user inputs "Hello" but the text output will be "Hi"?
I have found this link: Android speech recognition pass data back to Xamarin Forms
but it only outputs the speech "Hello" as a text "Hello".
Speech recognition usually involves translating what you say into text.If you need to change its content, perhaps you can try to make some judgments directly after the transformation and make changes according to your requirements like change the result in the link above :
in MainActivity OnActivityResult:
const int VOICE = 10;
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == VOICE)
{
if (resultCode == Result.Ok)
{
var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
if (matches.Count != 0)
{
var textInput = matches[0];
if (textInput.Length > 500)
textInput = textInput.Substring(0, 500);
//make a judgment and change the value
if(textInput.Eques("hello")){
textInput = "Hi";
}
SpeechToText_Android.SpeechText = textInput;
}
}
SpeechToText_Android.autoEvent.Set();
}
}

Android-TV speech recognition with manual input

I've implementing voice-search on my Android-TV app using the following small code
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
#Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == -1) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
Toast.makeText(getActivity(), spokenText, Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
This is all working well and I get the result back for further processing.
The problem is that I also want to give the user the possibility to enter the search-string manually with the virtual keyboard.
In Googles own apps you do this be simply pressing RIGHT on the remote to give focus to the textbox after pressing the voice-search icon.
In my example above I can see the "built-in-textbox" when I press the search icon but if I try to navigate to it the search is interrupted and closed.
How do I access the search-textbox? This should cancel voice-input and bring up the keyboard instead, just like Play Store app.
Are you using Leanback support library for your Android TV app design?
I guess "Google Play Store app" and "YouTube app" are using BrowseFragment & SearchFragment for search. These Fragments are providing build-in search UI.
For the implementation, see Google's sample source code or SearchFragment – Android TV app Tutorial 12.

Offline Speech Recognition in Android

I searched a lot on StackOverFlow for this Problem but the Threads are older than 3 years old.
I implemented the Google Voice Recognition which requires a Internet Connection. Searching how i can use the Offline Voice Recognition brought no success.
Is it now available to use the Voice Recognition when you're offline?
My code until yet:
speechStartButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
promtSpeechInput();
}
});
private void promtSpeechInput() {
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,
"Recording...");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CAMERA_PIC_REQUEST: {
try {
Bitmap image = (Bitmap) data.getExtras().get("data");
ImageView imageView = (ImageView) findViewById(R.id.taskPhotoImage);
imageView.setImageBitmap(image);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
case REQ_CODE_SPEECH_INPUT: {
if(resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
speechToTextField.setText(speechToTextField.getText()+" " +result.get(0));
}
break;
}
}
}
King Regards
Not with Google.
You have to use another solution like CMU Sphinx.
Check here : Android: Speech Recognition without using google server
Actually you can use SpeechRecognizer offline.
Go to Setting -> “Language and Input”
Choose the keyboard from “Keyboard & Input methods” section and enable “Google Voice Typing“
Go back to the previous screen “Language & input“, you will see the “Google voice typing” enabled.
Tap on “Offline speech recognition“.
Download the languages.
Now you should be able to use Speech To Text in offline mode.
The problem with this is it is not continuous without using a loop and using a loop with SpeechRecognizer is absolutely annoying due to the constant beeping sound. There are ways around the beeping sound but most of them mute the beeping sound and everything on the same audio stream as it.
Also mentioned in the steps, you also have to download "Google Voice Typing" and a language for it taking up a lot more storage space. Overall you can use SpeechRecognizer offline but it's a major hassle.

Android specific words speech recognition

I am trying to have the app recognize certain words said by the user using the code below, but for some reason it isn't working at all. Please review this and tell me what is wrong with it. Thank you
The app is simply suppose to display a toast message if the words "orange" or "apple" is said but nothing happens when using the code below.
//button onclick to trigger RecognizerIntent
public void OnClick_Speed_Detector(View v)
{
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "speak up");
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 1 && resultCode == RESULT_OK)
{
ArrayList<String> result =
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if(((result).equals("orange")))
{
Toast.makeText(getApplicationContext(), "orange", Toast.LENGTH_LONG).show();
}
else
if (((result).equals("apple")))
{
Toast.makeText(getApplicationContext(), "apple", Toast.LENGTH_LONG).show();
}
}
}
Your issue is that you are testing if an ArrayList == a String, when it can't possibly (an ArrayList of type String contains multiple strings)
Instead of:
if ((result).equals("orange")) {}
Try:
if ((result).contains("orange")) {}
This code will look through every index of the ArrayList and determine if any of the indexes of it equal "orange". If any do then it will return
true
...and it will execute the if statement!
Hope this helps!

Making the device speak text on command

I am having difficulty in framing this question but anyways here it goes, I have made two applications basically the TextToSpeech app and the SpeechToText application. They are working fine, now I am trying to merge them. Basically I want the the text to speech part to say the text entered in a text field , only if the user says the word "speak".That would be done using the speech to text part. Now the problem I am having is that android displays a list of outputs when the user says something, but I only one output that is "Speak" . How can I get only one output instead of a list.
Initially the app becomes active on button click.
The code I am trying is as follows:
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "system Activated");
startActivityForResult(i, check);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == check && resultCode == RESULT_OK) {
String command = data
.getStringExtra(RecognizerIntent.EXTRA_RESULTS).toString();
if (command.equals(command_verify)) {
speak();
} else
finish();
}
super.onActivityResult(requestCode, resultCode, data);
}
public void speak() {
String text_to_speak = message_field.getText().toString();
talk.speak(text_to_speak, TextToSpeech.QUEUE_FLUSH, null);
}
The Voice Recognizer returns you a list of guesses, where the first guess is the most accurate. You can use it calling list.get(0). Hope this helps.

Categories

Resources