禁用识别听众的“就绪"声音 [英] Disable 'Ready' sound of recognition listener

查看:56
本文介绍了禁用识别听众的“就绪"声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在选项卡式片段活动中实现了 RecognitionListener .发生的情况是,随着用户的滚动,会创建/销毁实现侦听器的片段,并且在我的Nexus 7和Galaxy Nexus上,您会听到与RegonitionListener关联的声音,或者它的SpeechRecognizer ,随时可以使用.不管是哪种类型的声音,我都希望允许用户将其禁用.我意识到当前的问题是我在听时没有解决用户关注的问题;但是,我仍然不想默认听到声音,而是希望让用户选择接收通知声音.

I implement a RecognitionListener inside of a tabbed fragment activity. What happens is that as the user scrolls around, the fragment that implements the listener is created/destroyed and on my Nexus 7 and Galaxy Nexus you hear a sound associated to the RegonitionListener, or maybe its the SpeechRecognizer, being ready for use. Whichever class is the cause of the sound, I would like to allow the user to disable it. I realize currently my issue is that I am listening without the users focus which I am resolving; however, I still do not want to hear the sound by default and prefer to let the user opt into the notification sound.

所以我的问题是,是否可以禁用与侦听器关联的通知声音?我一直无法在文档中找到它.

So my question is this, is it possible to disable the notification sound associated to the listener? I have been unable to find this in the docs.

推荐答案

正如zapl所说,没有直接的方法可以做到这一点,但是您可以尝试使系统容量静音,而腾讯则表示您正在避免使用任何一种方法.骇客.然后,我必须说没有办法做到这一点,但是,我仍然针对那些遭受相同问题并且可能不介意骇客"把戏的人分享此把戏解决方案.只是节省他们的无聊时间.

As zapl said that there is no direct method to do that but you can try muting the system volume and as you, Tencent said that you are avoiding any kind of hack. Then I must say there is no method SO FAR to do this, But still I'm sharing this trick solution for those who are suffering from same issue and may not mind a "hack" trick. Just saving their hours of frustration.

在该特定时间将系统音量静音,然后再取消静音.操作方法:

Mute the system volume for that particular time then un-mute after. How to do this:

在您的班级中,创建以下对象

In your class, create following objects

private AudioManager mAudioManager;
private int mStreamVolume = 0; 

在您的 onCreate 方法中执行以下操作.

In your onCreate method do following.

mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

当您开始收听语音识别时,请执行以下操作

When you start listening for Speech Recognition, do following

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 方法.

In your Speech RecognitionListener interface there should be a method 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
  }
}

这是您可以用这种令人讨厌的声音玩把戏的方法.显然,其他声音也会静音一秒钟.

This is how you can play a trick with this annoying sound. Obviously any other sound will also be mute for a second.

这篇关于禁用识别听众的“就绪"声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆