androidthings / sample-googleassistant

Google Assistant API sample for Android Things
Apache License 2.0
467 stars 147 forks source link

Can I use 3.5mm jack earphone or Speakers as output device(Board: PI3) #50

Closed codingspirit closed 6 years ago

codingspirit commented 6 years ago

Hi guys, USE_VOICEHAT_I2S_DAC has been set false. I tried to use USB audio card, everything is OK. Now I'm trying to use a USB microphone to record voice and use 3.5mm cable on PI3 to output. System can record voice and do recognition but there is no output on 3.5mm cable. When I tried to use findAudioDevice to get output device, return value is always null. Thanks o.O

codingspirit commented 6 years ago

First of all, if you are connected HDMI cable, pi3 will set HDMI as default audio output. And this solution might only works WITHOUT HDMI cable connecting. Solution: If you are not using voice hat, change line 58 to : private static final boolean USE_VOICEHAT_I2S_DAC = false; Then below line 98 and 99 :

AudioDeviceInfo audioInputDevice = null;
AudioDeviceInfo audioOutputDevice = null;

Set audioInputDevice as your device, in my case, I use a usb mic, so it will be: audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_USB_DEVICE); Also set audioOutputDevice: audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);//for 3.5mm And done. Sorry to closed this issue without write any solution. I thought I just make a stupid mistake and this solution is not worth mentioning.