AMI-system / ami_setup

AMI configuration files
MIT License
0 stars 2 forks source link

Need solution for when card number (randomly) switches and breaks arecord command #7

Closed gls21 closed 10 months ago

gls21 commented 1 year ago

A device name is needed for arecord to record audio. The device name is made up of a card number and device number in the format: plughw:cardnumber,devicenumber (find these with arecord -l).

The USB mic I have been using is identified with plughw:1,0.

However, on a couple of occasions, it wasn’t recording audio, and this was because (for a yet unknown reason) the device name changed to either plughw:2,0 or plughw:5,0.

These resources look useful: • https://forums.raspberrypi.com/viewtopic.php?t=244810
https://stackoverflow.com/questions/43361613/how-can-i-identify-multiple-usb-sound-cards

gls21 commented 10 months ago

I tried quite a few things that didn't work including the resources above - said permission denied even when using sudo.

Eventually, found and followed this resource: https://alsa.opensrc.org/Udev#Identify_two_identical_audio_devices - specifically this section: Writing udev rules - Identify two identical audio devices. Basically change the way the mic is identified - use name which never changes, rather than card number which can.

I just followed it but only did it for one device (whereas they do it for 2).

  1. Used cat /proc/asound/cards to show device name before - the dodo mic was r0.
  2. Then skipped down to bit in guide where it says to "Create a file like "/etc/udev/rules.d/85-my-usb-audio.rules" " which I did. I used sudo nano /etc/udev/rules.d/85-my-usb-audio.rules to create and write in it. Copied the website's template.
    • I called the mic "dodoMic".
    • The device path came from running: ls -la /sys/class/sound - it was the card 1 one, with 'usb' in the path
  3. Then unplugged the mic and plugged it back in.
  4. Then re-ran cat /proc/asound/cards, which showed the updated device name is dodoMic.
  5. Ran the birdRecording.py script with both plughw:1,0 and plughw:dodoMic,0 and both worked.

Did re-boot - changes remain and birdRecording.py still working with the new way of identifying the mic.

N.B. Not sure if will have to do this for every AMI set-up as the mic device path will likely be different??

change_mic_name