正如 zapl 所说,没有直接的方法可以做到这一点,但您可以尝试将系统音量静音,正如您一样,腾讯表示您正在避免任何形式的黑客攻击。然后我必须说目前还没有方法可以做到这一点,但我仍然在为那些遭受同样问题并且可能不介意“黑客”技巧的人分享这个技巧解决方案。只是为了节省他们的挫败感。
在特定时间将系统音量静音,然后取消静音。如何做到这一点:
在您的班级中,创建以下对象
private AudioManager mAudioManager;
private int mStreamVolume = 0;
在您的 onCreate 方法中执行以下操作。
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
当您开始收听语音识别时,请执行以下操作
speechRecognizer.startListening(intent); // this method make that annoying sound
mStreamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); // getting system volume into var for later un-muting
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // setting system volume to zero, muting
在您的语音 RecognitionListener 界面中应该有一个方法 onReadyForSpeech。
class MyRecognitionListener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params)
{
// this methods called when Speech Recognition is ready
// also this is the right time to un-mute system volume because the annoying sound played already
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mStreamVolume, 0); // again setting the system volume back to the original, un-mutting
}
}
这就是你可以用这种烦人的声音来玩把戏的方法。显然任何其他声音也会静音一秒钟。