How To Hide Toast Message “your Audio Will Be Sent To Google To Provide Speech Recognition Service.” In Android?
I am using google speech recognizer for integrating voice services in Android but while pressing on mic button this annoying toast message is showing. Please suggest me a way to hi
Solution 1:
Based on android regulations you cannot hide system toast messages as you don't have the accesses to the system View,
only in jailbrake android where you have access to the terminal you can try to do that.
Solution 2:
You can make a custom speech recogniser which will give you more control over the UI. MainActivity opens a new DialogFragment which implements RecognitionListener .
publicclassMainActivityextendsAppCompatActivityimplementsVoiceRecognizerInterface {
Button button ;
TextView textView;
Stringstring;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
textView = findViewById(R.id.textView);
button.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager != null && fragmentManager.findFragmentByTag("dialogVoiceRecognizer") == null && !isFinishing()) {
VoiceRecognizerDialogFragment languageDialogFragment = newVoiceRecognizerDialogFragment(MainActivity.this,MainActivity.this);
languageDialogFragment.show(fragmentManager, "dialogVoiceRecognizer");
}
}
});
}
@OverridepublicvoidspokenText(String spokenText) {
textView.setText(spokenText);
}
}
An interface to signal the main activity after stt.
publicinterfaceVoiceRecognizerInterface {
voidspokenText(String spokenText);
}
The custom SpeechToText Dialog.
publicclassVoiceRecognizerDialogFragmentextendsDialogFragmentimplementsRecognitionListener{
ImageView micImage;
TextView stateTV;
TextView displayTV;
privateSpeechRecognizer mSpeechRecognizer;
privateIntent mSpeechRecognizerIntent;
privateContext context;
VoiceRecognizerInterface signal;
@SuppressLint("ValidFragment")
publicVoiceRecognizerDialogFragment(Context context, VoiceRecognizerInterface signal) {
this.context = context;
this.signal = signal;
}
publicVoiceRecognizerDialogFragment(){
}
@Nullable@OverridepublicViewonCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.voice_recognizer_custom_layout ,container, false );
//Mic tap to listen again
micImage = view.findViewById(R.id.micImageView);
//Displays Listening.. when recognizer is listening
stateTV = view.findViewById(R.id.stateTV);
//Displays message if error
displayTV = view.findViewById(R.id.displayTV);
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
mSpeechRecognizerIntent = newIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
//Customize language by passing language code
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en");
//To receive partial results on the callback
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
context.getPackageName());
mSpeechRecognizer.setRecognitionListener(this);
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
micImage.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
startListening();
}
});
return view;
}
publicvoidstartListening(){
mSpeechRecognizer.setRecognitionListener(this);
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
changeUIStateToListening();
}
@OverridepublicvoidonDestroy() {
super.onDestroy();
if (mSpeechRecognizer != null) {
mSpeechRecognizer.destroy();
}
}
@OverridepublicvoidonBeginningOfSpeech()
{
}
@OverridepublicvoidonBufferReceived(byte[] buffer)
{
}
@OverridepublicvoidonEndOfSpeech()
{
}
@OverridepublicvoidonError(int error)
{
if(error == 7){
changeUIStateToRetry();
}
}
@OverridepublicvoidonEvent(int eventType, Bundle params)
{
}
@OverridepublicvoidonPartialResults(Bundle partialResults) {
}
@OverridepublicvoidonReadyForSpeech(Bundle params)
{
}
@OverridepublicvoidonResults(Bundle results)
{
ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if(matches == null){
return;
}
int i =0;
String first ="";
for(String s : matches){
if(i==0){
first = s;
}
i++;
}
// sending text to MainActivity using Interface
signal.spokenText(first);
this.dismiss();
}
@OverridepublicvoidonRmsChanged(float rmsdB)
{
}
publicvoidchangeUIStateToListening(){
displayTV.setText("Tell us what you need");
stateTV.setText("Listening...");
}
publicvoidchangeUIStateToRetry(){
displayTV.setText("Didn't catch that. Try\nSpeaking again");
stateTV.setText("Tap on mic to try again");
}
}
Post a Comment for "How To Hide Toast Message “your Audio Will Be Sent To Google To Provide Speech Recognition Service.” In Android?"