其他分享
首页 > 其他分享> > 如何隐藏Toast消息“你的音频将被发送到谷歌提供语音识别服务.”在Android?

如何隐藏Toast消息“你的音频将被发送到谷歌提供语音识别服务.”在Android?

作者:互联网

我正在使用谷歌语音识别器在Android中集成语音服务,但在按下麦克风按钮时,这个恼人的吐司消息正在显示.请建议我隐藏此Toast消息的方法.

这是我的java代码

public class FormActivity extends AppCompatActivity {

    AppCompatEditText mFeedbackView; 
    ImageView mFeedbackVoiceView;
    private final int REQ_CODE_SPEECH_INPUT_FEEDBACK = 100;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_form);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mVisitFeedbackView = findViewById(R.id.feedback);
        mFeedbackVoiceView = findViewById(R.id.feedback_voice);

        mFeedbackVoiceView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                promptSpeechInputFeedback();
            }
        });
    }
    private void promptSpeechInputFeedback() {
        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));
        try {
            startActivityForResult(intent, REQ_CODE_SPEECH_INPUT_FEEDBACK);
        } catch (ActivityNotFoundException a) {
            Toast.makeText(getApplicationContext(), getString(R.string.speech_not_supported), Toast.LENGTH_SHORT).show();
        }
    }

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

        switch (requestCode) {
            case REQ_CODE_SPEECH_INPUT_FEEDBACK: {
                if (resultCode == RESULT_OK && null != data) {
                    ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 
                    mFeedbackView.setText(result.get(0));
                }
                break;
            }  
        }
    }
}

这个问题与How to hide toast“ Your audio will be sent to google to provide speech recognition service.” in Speech Recognizer?重复,但没有解决方案.

任何帮助将不胜感激.

解决方法:

基于android规则
您无法隐藏系统Toast消息,因为您没有访问系统视图,

只有在jailbrake安卓才能访问终端,你可以尝试这样做.

标签:speech-to-text,android,speech-recognition
来源: https://codeday.me/bug/20190828/1747173.html