如何在树莓派3上为Google Assistant SDK安装USB声卡驱动及排查识别故障
Hey there, let's work through getting your USB sound card recognized and set up for the Google Assistant SDK on your Raspberry Pi 3. I’ve dealt with this exact scenario a few times, so here’s a step-by-step guide to get you up and running:
Before diving into software fixes, let’s eliminate simple hardware problems:
- Try plugging the USB sound card into a different USB port on the Pi (preferably one of the blue USB 3.0 ports, though USB 2.0 works too).
- Swap out the USB cable if you have a spare—sometimes faulty cables cause detection failures.
- Test the sound card on another computer (like a laptop) to confirm it works at all. If it doesn’t, the card itself might be defective.
Let’s verify the system sees the hardware:
- Open a terminal and run this command to list all USB devices:
lsusb
Look for an entry related to your sound card—something likeC-Media Electronics, Inc. Audio Adapteror the brand name of your device. If you don’t see it, the Pi isn’t detecting the hardware at all (go back to step 1). - Next, check if ALSA (the Pi’s audio system) recognizes the card as an audio device:
aplay -l(lists playback devices)arecord -l(lists recording devices)
You should see your USB sound card listed here, with a card number (e.g.,card 1) and device number (e.g.,device 0). Jot these down—you’ll need them later.
Most USB sound cards are plug-and-play on Raspberry Pi OS, but we can ensure all necessary packages are installed:
- Update your system packages first:
sudo apt update && sudo apt upgrade -y - Install ALSA utilities and common audio firmware:
sudo apt install alsa-utils firmware-linux-free -y - Reboot your Pi to apply any changes:
sudo reboot
The Google Assistant SDK will use the system’s default audio device, so we need to make sure the USB card is prioritized:
- Create or edit the ALSA configuration file for your user:
nano ~/.asoundrc - Paste the following content, replacing
card 1anddevice 0with the numbers you noted fromaplay -l:pcm.!default { type hw card 1 device 0 } ctl.!default { type hw card 1 } - Save the file (press
Ctrl+O, thenEnter) and exit nano (Ctrl+X). - Alternatively, you can edit the system-wide ALSA config if you want the change to apply to all users:
sudo nano /usr/share/alsa/alsa.conf
Find lines starting withdefaults.ctl.cardanddefaults.pcm.cardand change their values to your USB card’s number.
Let’s confirm the audio works before setting up the SDK:
- Test playback with a sample sound:
aplay /usr/share/sounds/alsa/Front_Center.wav
You should hear audio through the USB speaker. - Test recording (press
Ctrl+Cafter 5 seconds to stop):arecord -d 5 test.wav - Play back the recording to check the microphone:
aplay test.wav
If this works, your audio setup is good to go.
If you’ve already installed the SDK, make sure it’s using the correct audio devices:
- When running the push-to-talk sample, specify the audio devices explicitly using the card/device numbers:
googlesamples-assistant-pushtotalk --audio-input-device=hw:1,0 --audio-output-device=hw:1,0 - If you’re using the SDK in a custom script, ensure your code references the USB sound card instead of the Pi’s built-in audio.
- If you still don’t see the sound card in
aplay -l, check if your user has audio permissions:groups
Ifaudioisn’t listed, add your user to the group:sudo usermod -aG audio $USER
Then log out and back in, or reboot. - Some niche USB sound cards might require specific drivers. If you know the exact model, search for its Linux driver (but most common cards work with the default ALSA setup).
内容的提问来源于stack exchange,提问作者Sravan kunnummal.

