Android - MIC external for speechRecognition

↘锁芯ラ 提交于 2019-12-06 10:53:50

问题


I need to know which event is triggered when connecting a microphone or a headset to your device, and I am using speech recognition and have observed that does not follow the same flow as when nothing is connected to the device.

I would like to know if there is some kind of solution because the application I'm creating at the moment is tested in a Smartphone, but in the future will require connecting a microphone or a headset.

A greeting and I hope your answers

PS: At the moment in the code I have nothing on external microphone or headset, but at the moment everything is running according to device microphone and speaker.

EDIT

I see the way of knowing whether the headset is connected is as follows:

private class MusicIntentReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getIntExtra("state", -1);
        switch (state) {
        case 0:
            Log.d(TAG, "Headset is unplugged");
            break;
        case 1:
            Log.d(TAG, "Headset is plugged");
            break;
        default:
            Log.d(TAG, "I have no idea what the headset state is");
        }
    }
}
}

But how to redirect the audio input to the microphone of the headset? and the audio output to the headphone output?

来源:https://stackoverflow.com/questions/38220365/android-mic-external-for-speechrecognition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!