Set audio output using command line

8,306

This 2018 article explains how you can dynamically switch the audio output between hdmi and analogue on a Raspberry Pi. From the command line use

amixer cset numid=3 2

for hdmi and

amixer cset numid=3 1

for analogue. This information is no longer in the current version of that page, so may no longer work. The May 2020 blog says they have changed the sound architecture to handle the hdmi and analogue output as 2 independent devices: Alsa card 0 will be HDMI, and card 1 will be the headphone jack. The default is 0, but to use 1 you can create a ~/.asoundrc file with

defaults.pcm.card 1
defaults.ctl.card 1

This presumably requires you to login again.

You can generate a stereo test tone with another command from alsa-utils:

speaker-test -c 2 -s 1 -t sine -f 440
Share:
8,306

Related videos on Youtube

Johannes Lemonde
Author by

Johannes Lemonde

Updated on September 18, 2022

Comments

  • Johannes Lemonde
    Johannes Lemonde over 1 year

    I use the cmus console music player through ssh on a device with OSMC (Kodi, based on Debian Jessie) installed. My problem is that the sound is played to the HDMI, and I want to play music to the jack output.

    I tried to use alsamixer, amixer, aplay, etc... but these are not installed and sudo apt-get install alsamixer doesn't help. (Package not found - Maybe there's a better option than installing alsamixer anyway).

    I tried to read man cmus, which seems to offer the possibility to change some alsa settings : link to the online manual page, but I don't understand which settings are relevant for me, nor which values to put... Anyway : cmus is maybe not the source of my issue.

    How can I achieve what I want to, using only the terminal (I am through SSH) ?

    --

    PS : I finally installed alsamixer (actually the package's name was alsa-utils). And results that my jack output is not recognised. But I know it is working since other programs use it.

    • dirkt
      dirkt about 6 years
      Do you run Pulseaudio (check with ps axu)? If no, alsamixer and amixer are in package alsa-utils. If yes, use pacmd (see pacmd help).
    • Johannes Lemonde
      Johannes Lemonde about 6 years
      No I don't. I have installed alsa-utils, but it doesn't help : I can't find my jack output port in order to select it
    • dirkt
      dirkt about 6 years
      Hm. You wrote device, so what kind of device exactly? Maybe something exotic? Please edit question with output of lspci -nn | grep Audio, cat /proc/asound/pcm and lsmod | grep snd.
    • meuh
      meuh about 6 years
      My answer assumed you were on a raspberry pi, for some reason (osmc, hdmi, jack plug). if not, add the output of aplay --list-devices to your post.
  • abc
    abc over 3 years
    There is no explaination of what meur is doing. Also the source linked to the same none intelligible documentation type as complained about in the question. It also only linked a start page, not even to a relevant place. Might of as well pointed to the moon when talking about sandstone, it is equivalent to that, be there for hours, and most will get lost or far to many even its one and will die there before they ever found out what sandstone is. I had to read entire pages of that book to get to nothing at all, and after all that it was only a copy paste of the man page, it added nothing.
  • abc
    abc over 3 years
    A mnemonic device, like a doctors secret writing system or the laziest that can possibly do in life. It it was more of the exactly the same codified jargon. Like some dependency hell program. It had great potential but was undermined by industry personnel and the bourgeoisie which GNU/Linux/* had sworn an allegiance to combat.
  • meuh
    meuh over 3 years
    Sadly, the web page has changed a lot from 2018, so it is no longer obvious where to find the information, and the actual information has even been removed from the documentation. Perhaps this means the above no longer works. I've updated the link to the archive.org versioon of the page. If you are using raspian from May 2020 the audio architecture has changed, see the blog under Other Changes.