gpt4 book ai didi

java - setStreamMute(STREAM_RING) 静音文本转语音 android

转载 作者:行者123 更新时间:2023-12-01 14:22:53 25 4
gpt4 key购买 nike

我正在尝试说出一些文字。由于某些奇怪的原因,静音 STREAM_RING 也使文本转语音静音。我在互联网上搜索过,但我想以前没有人遇到过这个问题,所以我找不到答案。这是我的代码:

int volume=0;

if(state == TelephonyManager.CALL_STATE_RINGING)
{
Toast.makeText(getApplicationContext(), "Inside", Toast.LENGTH_SHORT).show();

if(incomingNumber != null)
{
volume= audioManager.getStreamVolume(AudioManager.STREAM_RING);


audioManager.setStreamMute(AudioManager.STREAM_RING, true);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_ALLOW_RINGER_MODES);
tts.speak(incomingNumber, TextToSpeech.QUEUE_FLUSH, null);

Toast.makeText(getApplicationContext(), "speak number", Toast.LENGTH_SHORT).show();
}


if(state == TelephonyManager.CALL_STATE_IDLE)
{
audioManager.setStreamVolume(AudioManager.STREAM_RING, volume, AudioManager.FLAG_ALLOW_RINGER_MODES);
audioManager.setStreamMute(AudioManager.STREAM_RING, false);
}
}
}

最佳答案

int mRingerMode;

Toast.makeText(getApplicationContext(), "INCOMING CALL", Toast.LENGTH_SHORT).show();

if(state == TelephonyManager.CALL_STATE_RINGING)
{
Toast.makeText(getApplicationContext(), "Inside", Toast.LENGTH_SHORT).show();

if(incomingNumber != null)
{
mRingerMode = audioManager.getRingerMode();
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
new Thread(new Runnable()
{
@Override
public void run()
{
HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
String.valueOf(AudioManager.STREAM_VOICE_CALL));
tts.speak(incomingNumber, TextToSpeech.QUEUE_FLUSH, myHashRender);
}
}).start();

Toast.makeText(getApplicationContext(), "speak number", Toast.LENGTH_SHORT).show();
}


if(state == TelephonyManager.CALL_STATE_IDLE)
{
audioManager.setRingerMode(mRingerMode);
}
}

}

关于java - setStreamMute(STREAM_RING) 静音文本转语音 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17392823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com