Raspberry Pi – Audio afspelen via Jackplug / USB Audio
Deze pagina beschrijft het afspelen van audio op een Raspberry Pi, zowel via de Jackplug als een USB soundcard.
Ik heb onlangs een Logitech Socom (blijkt een PS2 headset) gekocht in de kringloop voor 1 euro:
1 |
Bus 001 Device 004: ID 046d:0a01 Logitech, Inc. USB Headset |
Om audio af te spelen zou ik aanraden om Mplayer te gebruiken (ipv omxplayer), deze kan ook met streams overweg.
omxplayer
Download het voorbeeld mp3 bestand met het commando:
wget https://goo.gl/XJuOUW -O example.mp3 --no-check-certificate
Geluid afspelen via HDMI met het commando:
omxplayer -o hdmi example.mp3
Geluid afspelen via Koptelefoon plug met het commando:
omxplayer -o local example.mp3
Mplayer
Mplayer installeren
Mplayer is niet standaard op Raspbian geinstalleerd, installeer Mplayer met het commando: sudo apt-get install mplayer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'mplayer2' instead of 'mplayer' The following extra packages will be installed: liba52-0.7.4 libbs2b0 liblircclient0 liblua5.2-0 libpostproc52 libquvi-scripts libquvi7 Suggested packages: lirc The following NEW packages will be installed: liba52-0.7.4 libbs2b0 liblircclient0 liblua5.2-0 libpostproc52 libquvi-scripts libquvi7 mplayer2 0 upgraded, 8 newly installed, 0 to remove and 73 not upgraded. Need to get 1,042 kB of archives. After this operation, 2,711 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblua5.2-0 armhf5.2.3-1.1 [64.8 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libquvi-scripts all 0.4.21-2 [37.3 kB] Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libquvi7 armhf 0.4.1-3 [18.1 kB] Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main liba52-0.7.4 armhf 0.7.4-17 [28.9 kB] Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblircclient0 armhf 0.9.0~pre1-1.2 [33.0 kB] Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpostproc52 armhf 6:0.git20120821-4 [28.8 kB] Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libbs2b0 armhf 3.1.0+dfsg-2.1 [10.7 kB] Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main mplayer2 armhf 2.0-728-g2c378c7-4+b1 [820 kB] Fetched 1,042 kB in 1s (647 kB/s) Selecting previously unselected package liblua5.2-0:armhf. (Reading database ... 118511 files and directories currently installed.) Preparing to unpack .../liblua5.2-0_5.2.3-1.1_armhf.deb ... Unpacking liblua5.2-0:armhf (5.2.3-1.1) ... Selecting previously unselected package libquvi-scripts. Preparing to unpack .../libquvi-scripts_0.4.21-2_all.deb ... Unpacking libquvi-scripts (0.4.21-2) ... Selecting previously unselected package libquvi7:armhf. Preparing to unpack .../libquvi7_0.4.1-3_armhf.deb ... Unpacking libquvi7:armhf (0.4.1-3) ... Selecting previously unselected package liba52-0.7.4. Preparing to unpack .../liba52-0.7.4_0.7.4-17_armhf.deb ... Unpacking liba52-0.7.4 (0.7.4-17) ... Selecting previously unselected package liblircclient0. Preparing to unpack .../liblircclient0_0.9.0~pre1-1.2_armhf.deb ... Unpacking liblircclient0 (0.9.0~pre1-1.2) ... Selecting previously unselected package libpostproc52. Preparing to unpack .../libpostproc52_6%3a0.git20120821-4_armhf.deb ... Unpacking libpostproc52 (6:0.git20120821-4) ... Selecting previously unselected package libbs2b0. Preparing to unpack .../libbs2b0_3.1.0+dfsg-2.1_armhf.deb ... Unpacking libbs2b0 (3.1.0+dfsg-2.1) ... Selecting previously unselected package mplayer2. Preparing to unpack .../mplayer2_2.0-728-g2c378c7-4+b1_armhf.deb ... Unpacking mplayer2 (2.0-728-g2c378c7-4+b1) ... Processing triggers for man-db (2.7.0.2-5) ... Processing triggers for mime-support (3.58) ... Setting up liblua5.2-0:armhf (5.2.3-1.1) ... Setting up libquvi-scripts (0.4.21-2) ... Setting up libquvi7:armhf (0.4.1-3) ... Setting up liba52-0.7.4 (0.7.4-17) ... Setting up liblircclient0 (0.9.0~pre1-1.2) ... Setting up libpostproc52 (6:0.git20120821-4) ... Setting up libbs2b0 (3.1.0+dfsg-2.1) ... Setting up mplayer2 (2.0-728-g2c378c7-4+b1) ... Processing triggers for libc-bin (2.19-18+deb8u4) ... |
Het gebruik van Mplayer is als volgt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
Creating config file: /home/pi/.mplayer/config Usage: mplayer [options] [url|path/]filename Basic options: (complete list in the man page) -vo <drv> select video output driver ('-vo help' for a list) -ao <drv> select audio output driver ('-ao help' for a list) vcd://<trackno> play (S)VCD (Super Video CD) track (raw device, no mount) dvd://<titleno> play DVD title from device instead of plain file -alang/-slang select DVD audio/subtitle language (by 2-char country code) -ss <position> seek to given (seconds or hh:mm:ss) position -nosound do not play sound -fs fullscreen playback (or -vm, -zoom, details in the man page) -x <x> -y <y> set display resolution (for use with -vm or -zoom) -sub <file> specify subtitle file to use (also see -subfps, -subdelay) -playlist <file> specify playlist file -vid x -aid y select video (x) and audio (y) stream to play -fps x -srate y change video (x fps) and audio (y Hz) rate -pp <quality> enable postprocessing filter (details in the man page) -framedrop enable frame dropping (for slow machines) Basic keys: (complete list in the man page, also check input.conf) <- or -> seek backward/forward 10 seconds down or up seek backward/forward 1 minute pgdown or pgup seek backward/forward 10 minutes < or > step backward/forward in playlist p or SPACE pause movie (press any key to continue) q or ESC stop playing and quit program + or - adjust audio delay by +/- 0.1 second o cycle OSD mode: none / seekbar / seekbar + timer * or / increase or decrease PCM volume x or z adjust subtitle delay by +/- 0.1 second r or t adjust subtitle position up/down, also see -vf expand double click toggle fullscreen right click pause (press again to continue) * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * * |
Voorbeelden
Mp3 bestand afspelen via koptelefoon jack:
mplayer -ao alsa example.mp3
Mp3 bestand afspelen via USB audio:
mplayer -ao alsa:device=hw=1,0 example.mp3
Stream afspelen via koptelefoon jack:
mplayer -vo null -ao alsa -playlist http://playlist.olympia-classics.nl/luister/playlist.m3u
Stream afspelen via USB audio:
mplayer -vo null -ao alsa:device=hw=1,0 -playlist http://playlist.olympia-classics.nl/luister/playlist.m3u
Audio bestand / Stream afspelen in de achtergrond (voorbeeld):
mplayer -vo null -ao alsa -noconsolecontrols -playlist http://playlist.olympia-classics.nl/luister/playlist.m3u &
Opnemen van audio via microfoon van USB Headset:
arecord -D plughw:1 -r 44000 test.wav
afspelen opgenomen audiobestand:
mplayer -ao alsa test.wav
Bronnen:
raspberrypi.org
raspberrypi.org
superuser.com
bbs.archlinux.org
raspberrypi.org