2

好的,在 Jelly Bean SpeecRecognizer 中有哔声...我希望在旧版本中具有相同的声音(或我选择的声音)。

我现在正在这样做

                int currentapiVersion = android.os.Build.VERSION.SDK_INT;
                if (currentapiVersion < android.os.Build.VERSION_CODES.JELLY_BEAN){
                        //prepare beep
                    beep.start();
                }
                //prepare intent
                sr.startListening(intent);

但是在哔声和聆听之间还有时间......如果在 jb 以下,我需要在 SpeechRecognizer 侦听器中的哪个位置开始发出哔声?

我想说我不想在录制时播放哔声,因为它会破坏我的识别!

而且,如果有人能找到我,JB 的哔哔声会很棒:)

4

1 回答 1

0

你可以把它放在 onReadyForSpeech 中(如果你实现了 RecogntionListener)

    public class MySpeechRecognizer implements RecognitionListener {
            public void initialize()
            {
                //... other SpeechRecognizer initialization
                mSpeechRecognizer.setRecognitionListener(this);
            }
            @Override
            public void onReadyForSpeech(Bundle params) {
                final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
                tg.startTone(ToneGenerator.TONE_PROP_BEEP);
           }
           //... other required methods of RecognitionListener
    }

唯一的问题是蜂鸣声将导致识别开始,因此如果您在 onError 中收到错误 7(无结果),则需要重新启动识别。

或者,我采用了振动解决方案(使用蓝牙耳机时除外)而不是哔哔声,因为语音识别不会检测到振动。

@Override
public void onReadyForSpeech(Bundle params) {
    Log.d("SpeechRecognizer", "Ready");
    if (beepOnReady && !hasBeeped) {
        Log.d("SpeechRecognizer", "Beeping");
        hasBeeped = true;
        if (beepOnBluetooth) {
            final ToneGenerator tg = new ToneGenerator(6, 100);
            tg.startTone(ToneGenerator.TONE_PROP_BEEP);
        }
        else
        {
            Vibrator vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) ;
            vibe.vibrate(50);
        }

    }
于 2013-07-03T20:33:32.970 回答