i am trying to use google offline speech recognition in my android app
which just converts speech into text but its not working. i have downloaded
offline language .
the same app works fine with internet connection on but doesn't work in
offline mode the main code is as follows:
package com.example.parth.texttospeech;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.speech.RecognizerIntent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
TextView resultTEXT;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButtonClick(View v)
{
if(v.getId()==R.id.bttexttospeech)
{
resultTEXT=(TextView)findViewById(R.id.tvresult);
prompSpeechInput();
}
}
public void prompSpeechInput()
{
Intent i=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,Locale.getDefault());
i.putExtra(RecognizerIntent.EXTRA_PROMPT,"say something");
try{
startActivityForResult(i,100);
}catch(ActivityNotFoundException e)
{
Toast.makeText(getApplicationContext(),"sorry device doesnt support
text to speech",Toast.LENGTH_LONG).show();
}
}
public void onActivityResult(int request_code, int result_code, Intent i) {
super.onActivityResult(request_code,result_code,i);
{
switch(request_code)
{
case 100:if(result_code==RESULT_OK && i!=null)
{
ArrayList<String>
result=i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
resultTEXT.setText(result.get(0));
break;
}
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/c01ec76a-9073-4d7c-9956-ed5350657eed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.