In most usage scenarios, the app runs outdoors with Bluetooth headphones, so I’ve implemented Bluetooth audio profile switching (SCO) to ensure that the microphone used is the Bluetooth one.
On some devices (e.g. Google Pixel 9), when I switch to the SCO profile and start the speech recognizer after SCO is confirmed active, I notice:
The start sound (beep) played by the system when startListening() is called is either inaudible or very low
On other Устройства, звук играет, но с низким объемом, особенно в режиме SCO < /p>
Я попытался увеличить громкость потока голосового вызова перед запуск распознавания речи, но это не помогло.
Код: Выделить всё
public void requestBluetoothMicRouting(@NonNull AudioManager audioManager, @NonNull BluetoothSCOAudioStateListener listener) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
boolean result = selectBluetoothMic(audioManager);
if (!result) {
listener.onBluetoothSCOAudioStateChanged(AudioManager.SCO_AUDIO_STATE_ERROR);
}
} else {
audioManager.startBluetoothSco();
}
}
@RequiresApi(api = Build.VERSION_CODES.S)
private boolean selectBluetoothMic(@NonNull AudioManager audioManager) {
for (AudioDeviceInfo deviceInfo : audioManager.getAvailableCommunicationDevices()) {
if (deviceInfo.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) {
return audioManager.setCommunicationDevice(deviceInfo);
}
}
return false;
}
Код: Выделить всё
if (BluetoothHeadsetHelper.getInstance().hasBluetoothHeadphonesConnected()) {
BluetoothHeadsetHelper.getInstance().requestBluetoothMicRouting(audioManager, state -> {
if (state != AudioManager.SCO_AUDIO_STATE_ERROR) {
MySpeechRecognizer.getInstance().startListening(Locale.getDefault().toLanguageTag());
}
});
} else {
MySpeechRecognizer.getInstance().startListening(Locale.getDefault().toLanguageTag());
}
< /code>
🧠 Реализация распознавания: < /h2>
public void startListening(String language) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
speechRecognizer.startListening(intent);
}
< /code>
📈 То, что я попробовал < /h1>
Настройка тома Stream_voice_call на максимум: < /p>
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);
reversing ording: sallStening () перед переключением звукового профиля →
Что приводит к тому, что система запуска системы отсутствует или едва слышал при использовании звуковой маршрутизации Bluetooth Sco? Я открыт для обходных путей или внутренних трюков, если они работают в большинстве версий Android.
Подробнее здесь: https://stackoverflow.com/questions/795 ... etooth-sco