balena os - upboard - audio playout issue

Hi all!
I’m working on a small project with a text-to-speech microservice.
We use an upboard cht01, with a usb sound card plugged in.

this is lsusb output on balena os host

Bus 001 Device 004: ID 0424:2530 Standard Microsystems Corp.

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 001 Device 002: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter

Bus 001 Device 003: ID 0424:4603 Standard Microsystems Corp.

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I also listed /dev content with and without plugged usb, and I notice that the only difference is hidraw0.

After that I create a docker compose in order to get a docker container with audio support, with a small node script to playout a local file by audio-play, audio-buffer-from and audio-loader npm packages

This is the docker compose

version: "2"
services:
  test:
    container_name: test
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - UDEV=1
    privileged: true
    devices:
      - "/dev/snd:/dev/snd"
      - "/dev/hidraw0:/dev/hidraw0"
    network_mode: host

and this is the dockerfile

FROM node:16.6-alpine
RUN adduser -S appuser

WORKDIR /usr/src/app

RUN apk update && \
  apk upgrade && \
  apk add \
  espeak \
  vorbis-tools \
  sox \
  alsa-utils \
  alsa-lib \
  pulseaudio \
  pulseaudio-alsa \
  pulseaudio-utils \
  curl \
  rm -rf /var/cache/apk/*

COPY package*.json ./
RUN npm i
COPY . .

RUN addgroup appuser audio
RUN addgroup appuser pulse
RUN addgroup appuser pulse-access

USER appuser

RUN pulseaudio --start

CMD tail -f /dev/null

in the docker container I can get available sound cards by aplay --list-devices command, but unluckily, it seems there is no sound card available.

aplay --list-devices
aplay: device_list:274: no soundcards found...

I think it’s just a docker compose device mount issue, but I have no idea about how to make it working… any helps?
Thanks! :slight_smile:

Hello folks,
Not sure if it would help or you already checked it out, but would our Audio block help in this case? It’s not supported on Upboard but maybe you can use it as a reference? GitHub - balenablocks/audio: Audio building block, based on pulseaudio.

great! thanks, I’ll check it out

Hello there, audio block dev here. I think you should def try the audio block or at least check it’s code for useful parts, it’s a pulseaudio based audio server so it’s probably close to what you want. Upboards are not supported but because I don’t have one and haven’t tested it, it’s likely it works just fine.

Regarding your problem, it does look like the device is not being picked up as a sound card by alsa. What are the contents of /proc/asound/cards?

hi @tmigone . thanks for your reply. in balena os host that folder seems empty, while in docker container it doesn’t exists

Hi @gzett, sorry I missed this ping and just noticed it.

That is super weird. Can you list the contents of the parent folde? Run ls -al /proc/asound in the HostOS. Also, what version of balenaOS are you using?

Balena OS version is

HOST OS VERSION
balenaOS 2.54.2+rev1
development
SUPERVISOR VERSION
11.12.4

and this is the command output

root@a38b613:~# ls -al /proc/asound                   
total 0
dr-xr-xr-x   6 root root 0 Sep 23 14:35 .
dr-xr-xr-x 139 root root 0 Sep 23 14:33 ..
lrwxrwxrwx   1 root root 5 Sep 23 14:35 Audio -> card0
lrwxrwxrwx   1 root root 5 Sep 23 14:35 Device -> card1
lrwxrwxrwx   1 root root 5 Sep 23 14:35 bytchtnocodec -> card2
dr-xr-xr-x   5 root root 0 Sep 23 14:35 card0
dr-xr-xr-x   4 root root 0 Sep 23 14:35 card1
dr-xr-xr-x   6 root root 0 Sep 23 14:35 card2
-r--r--r--   1 root root 0 Sep 23 14:35 cards
-r--r--r--   1 root root 0 Sep 23 14:35 devices
-r--r--r--   1 root root 0 Sep 23 14:35 hwdep
-r--r--r--   1 root root 0 Sep 23 14:35 modules
-r--r--r--   1 root root 0 Sep 23 14:35 pcm
dr-xr-xr-x   2 root root 0 Sep 23 14:35 seq
-r--r--r--   1 root root 0 Sep 23 14:35 timers
-r--r--r--   1 root root 0 Sep 23 14:35 version

thanks :slight_smile:

Hi @gzett, it looks like the hostOS is detecting the card (assuming it’s card1 listed there). We can confirm that if you share the output of cat /proc/asound/cards (again, run it on the hostOS).

If so, then it might be that the mapping to the container is somehow not working properly. Can you try deploying another container in privileged mode running debian and share the output of: ls -al /proc/asound and cat /proc/asound/cards. Here is a sample docker-compose.yml file you can use:

version: '2'

services:

  test:
    image: balenalib/up-board-debian
    privileged: true

Hi @tmigone , sorry for the late reply

this is cat /proc/asound/cards output in the host OS:

root@a38b613:~# cat /proc/asound/cards
 0 [Audio          ]: HdmiLpeAudio - Intel HDMI/DP LPE Audio
                      Intel HDMI/DP LPE Audio
 1 [Device         ]: USB-Audio - C-Media USB Audio Device
                      C-Media USB Audio Device at usb-0000:00:14.0-3, full speed
 2 [bytchtnocodec  ]: bytcht-nocodec - bytcht-nocodec
                      AAEON-UP_CHT01-V1.0-UP_CHT01

then I create a container like suggested and this is the results:

[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x   6 root root 0 Oct  6 13:22 .
[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x 132 root root 0 Oct  6 13:22 ..
[Logs]    [10/6/2021, 3:22:01 PM] [test] lrwxrwxrwx   1 root root 5 Oct  6 13:22 Audio -> card0
[Logs]    [10/6/2021, 3:22:01 PM] [test] lrwxrwxrwx   1 root root 5 Oct  6 13:22 bytchtnocodec -> card2
[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x   5 root root 0 Oct  6 13:22 card0
[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x   4 root root 0 Oct  6 13:22 card1
[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x   6 root root 0 Oct  6 13:22 card2
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 cards
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 devices
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 hwdep
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 modules
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 pcm
[Logs]    [10/6/2021, 3:22:01 PM] [test] dr-xr-xr-x   2 root root 0 Oct  6 13:22 seq
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 timers
[Logs]    [10/6/2021, 3:22:01 PM] [test] lrwxrwxrwx   1 root root 5 Oct  6 13:22 usb-soundcard-1 -> card1
[Logs]    [10/6/2021, 3:22:01 PM] [test] -r--r--r--   1 root root 0 Oct  6 13:22 version
[Logs]    [10/6/2021, 3:22:01 PM] [test]  0 [Audio          ]: HdmiLpeAudio - Intel HDMI/DP LPE Audio
[Logs]    [10/6/2021, 3:22:01 PM] [test]                       Intel HDMI/DP LPE Audio
[Logs]    [10/6/2021, 3:22:01 PM] [test]  1 [usb-soundcard-1]: USB-Audio - C-Media USB Audio Device
[Logs]    [10/6/2021, 3:22:01 PM] [test]                       C-Media USB Audio Device at usb-0000:00:14.0-3, full speed
[Logs]    [10/6/2021, 3:22:01 PM] [test]  2 [bytchtnocodec  ]: bytcht-nocodec - bytcht-nocodec
[Logs]    [10/6/2021, 3:22:01 PM] [test]                       AAEON-UP_CHT01-V1.0-UP_CHT01

I also execute cat /proc/asound/cards in the hostOS:

root@a38b613:~# cat /proc/asound/cards
 0 [Audio          ]: HdmiLpeAudio - Intel HDMI/DP LPE Audio
                      Intel HDMI/DP LPE Audio
 1 [usb-soundcard-1]: USB-Audio - C-Media USB Audio Device
                      C-Media USB Audio Device at usb-0000:00:14.0-3, full speed
 2 [bytchtnocodec  ]: bytcht-nocodec - bytcht-nocodec
                      AAEON-UP_CHT01-V1.0-UP_CHT01

thanks for your support :slight_smile: