由於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
}
}
這就是你如何玩這個惱人的聲音的伎倆。顯然任何其他聲音也會靜音一秒鐘。
我想聲音是由語音識別服務產生的,這意味着你的應用程序不太可能改變這種情況,特別是因爲我沒有在系統設置或官方語音搜索彈出窗口中看到有關該聲音的任何選項。您可以在語音識別過程中嘗試將音量靜音,但也可以將可能正在進行的背景音樂靜音。 – zapl 2012-08-14 12:12:54
當識別監聽器啓動時,背景音樂會被切斷。如果可能的話,我寧願避免使用黑客。道具的想法! – 2012-08-14 12:18:06