Установить ограничение времени записи звука для SpeechRecognizer - PullRequest
0 голосов
/ 04 февраля 2020

Я новичок в разработке Android, как установить ограничение времени для записи звука? Я хочу установить максимальное время записи 10 секунд, что мне нужно добавить в мой код. Ниже моя часть кодирования, я надеюсь, что кто-то может помочь мне решить эту проблему. Спасибо

final Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
                Locale.getDefault());
 findViewById(R.id.btnRecord).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_UP:
                        mSpeechRecognizer.stopListening();
                        //when the user removed the finger
                        message.setHint("You will see input here");
                        break;

                    case MotionEvent.ACTION_DOWN:
                        //finger is on the button
                        a.speak("Record", TextToSpeech.QUEUE_FLUSH,null);
                        Toast.makeText(getBaseContext(), R.string.record, Toast.LENGTH_SHORT).show();
                        mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
                        message.setText("");
                        message.setHint("Listening...");
                        break;
                }
                return false;


            }
        });

Добавить код здесь? установить максимальное время, где и как?

  mSpeechRecognizer.setRecognitionListener(new RecognitionListener() {
            @Override
            public void onReadyForSpeech(Bundle bundle) {

            }

            @Override
            public void onBeginningOfSpeech() {

            }

            @Override
            public void onRmsChanged(float v) {

            }

            @Override
            public void onBufferReceived(byte[] bytes) {

            }

            @Override
            public void onEndOfSpeech() {

            }

            @Override
            public void onError(int i) {

            }

            @Override
            public void onResults(Bundle bundle) {
                //getting all the matches
                ArrayList<String> matches = bundle
                        .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

                //displaying the first match
                if (matches != null)
                    message.setText(matches.get(0));
            }

            @Override
            public void onPartialResults(Bundle bundle) {

            }

            @Override
            public void onEvent(int i, Bundle bundle) {

            }
        });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...