Linux Command Line Audio.
by Computothought in Circuits > Linux
20390 Views, 7 Favorites, 0 Comments
Linux Command Line Audio.
What's needed:
Linux based computer.
A supported sound card.
Speakers or headset.
Microphone(s).
FM radio card ( or analog tv capture card that has a radio tuner.
Note: can do this on a gui based machine from a terminal also. If you are visually impaired, instructables like this can be very important.
Command Line Sound Recording.
$ sudo apt-get install sound-recorder
When recording from the command line the command is:
$ sound-recorder -c 2 -b 16 -P -S 5:00 recording.wav |
The options set stereo recording (-c 2), 16 bit sampling (-b 16), priority threading (-P) to ensure high priority in CPU usage, and limiting the recording to 5 minutes. The output is written to the file recording.wav.
Many of these options are the default so you can simply:
$ sound-recorder -P recording.wav |
or use
arecord: Linux Command to List all Soundcards and Digital Audio Devices
Here is a quick way to list all detected and working soundcards. Use arecord command line sound recorder and player for ALSA soundcard driver. The -l option List all soundcards and digital audio devices. The -L option list all PCMs defined. The information obtained from following command can be used to play various media files [...]
Record:
$ arecord filename.ext
Playback:
$ aplay filename.ext
Local Music Files.
$ sudo apt -get install mplayer
$ mplayer musicfilename
mplayer actually has a ton of oprions but it's simplest form will usally do the job.
Hint: file * can let you know what kind of files are in your directory.
$ cd 2011-12-03/
~/2011-12-03$ ls
hpr0861.ogg hpr0863.ogg hpr0865.ogg hpr0867.ogg hpr0869.ogg podcast.m3u
hpr0862.ogg hpr0864.ogg hpr0866.ogg hpr0868.ogg hpr0870.ogg
~/2011-12-03$ file *.ogg
hpr0861.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0862.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0863.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0864.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0865.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0866.ogg: Ogg data, Vorbis audio, mono, 22050 Hz, ~40222 bps, created by: Xiph.Org libVorbis I
hpr0867.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0868.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0869.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
hpr0870.ogg: Ogg data, Vorbis audio, mono, 44100 Hz, ~80000 bps, created by: Xiph.Org libVorbis I
~/2011-12-03$
Set the computer to wake you up an play reveille.
crontab -e
# run at 6 am on weekdays, to wake me up 0 6 * * 1-5 mplayer /home/you/reveille.mp3 ------------------------------
Anohter command line ,usic player is mpg123. I like to log in remotely into a server and start it. That way the machine I a using is not locked into that application.
Note mpg123 you can play either 1 song at a time or many one after the other. For a single song to be played in the background use:
$ mpg123 songfile.ext &
For many songs, create an ascii file with all the filenames including their location.
$ mpg123 -@ playlist &
Podcast Catcher.
i.e.
http://www.hackerpublicradio.org/hpr_ogg_rss.php
make a dir such as podcasts
Download and put bp.conf, bp.sh, and parse_enclosure.xsl3 into that directory.
change to that directory .
$ chmod +x bp.sh
$ ./bp.sh
vim or nano bp.conf and add your rss feeds.
http://www.hackerpublicradio.org/hpr_ogg_rss.php
Have computer get new podcasts once a week
#@weekly Run once a week. 0 0 * * 0 /home/yourname/musicdirectory/bp.sh When you want to hear a podcast, go to the music directory and use mplauer. There will be subdirectories by date.
MPD.
Love MPD. It is both a music player and an internet radio player. You can install this on a really old machine or a new arm based linux device. Just add an amp and speakers and you have a new age stereo that can be controlled remotely..
Make your directories where you want your music to be and then copy them there if they are not already there. Now to inbstall the basic software. You have the program itself (mpd)and a command line player to test it.(mpc)
$sudo apt-get install mpd mpc.
Sure sure your stero and or speakers are attached to the sound card and they work. Now to test it. We will do it with a radio station if you do not have any music to t4est with.
$ mpc add http://relay3.slayradio.org:8000/
adding: http://relay3.slayradio.org:8000/
$ mpc play
You should hear the radio station out of your speakers now.
Now let’s edit the config file for file location and to allow the server to be accesed from other systems. Warning this is not secure, as your better off sshing into the machine to control it.
$ sudo vim /etc/mpd.con
Change the directory where you files are (uncomment the line also
# Files and directories #######################################################
#
# This setting controls the top directory which MPD will search to discover the
# available audio files and add them to the daemon’s online database. This
# setting defaults to the XDG directory, otherwise the music directory will be
# be disabled and audio files will only be accepted over ipc socket (using
# file:// protocol) or streaming files over an accepted protocol.
#
# music_directory “/var/lib/mpd/music”
If you want to access the machine remotely you will need to change the hostname to the nmae of the michine, Warning: people will be albe to telnet into the machine unless you password protect the system.
#
# This setting sets the address for the daemon to listen on. Careful attention
# should be paid if this is assigned to anything other then the default, any.
# This setting can deny access to control of the daemon. Choose any if you want
# to have mpd listen on every address
#
# For network
# bind_to_address “localhost”
Permissions:
# Permissions #################################################################
#
# If this setting is set, MPD will require password authorization. The password
# can setting can be specified multiple times for different password profiles.
#
#password “password@read,add,control,admin”
#
# This setting specifies the permissions a user has who has not yet logged in.
#
#default_permissions “read,add,control,admin”
#
###############################################################################
There are other settings, but I will let you check that out your selves..
Now to access the system form other machines. There is a client for about every system known to man. You can check them out yourself at:
http://mpd.wikia.com/wiki/Clients
To ad a radio station, you most likely yhave to an a url.
Over the Internet Radio.
$ sudo apt-get install mpg123
you will need to get the website and port mo.
mpg321 website:portnimber
i.e.
$ mpg321 http://sc1.audiorealm.com:10074/e
in some cases you will have to download the playlist file and extract the the url:port. you can use links2 ot or elinks to grab the playlist name and then use wget to grab the file. once you have file you can extrat the url:portnumber.
i.e.
$ wget http://provisioning.streamtheworld.com/pls/KBPAFMAAC.pls
Som stations use the m3u format.
$ cat 96-32.m3u
http://sc1.audiorealm.com:10074/
The it is just a matter of running mpg123
$ mpg123 http://sc1.audiorealm.com:10074/
Some newer station require flash of a particular player to listen to their music. That is a subject for another day.
Over the Air Radio.
$ sudo apt-get install radio
To get the tuner card to search for stations you would:
$ radio i
and then to play the stations you would just
$ radio
--------------------------------------------------------------------
NAME
radio - console radio application
SYNOPSIS
radio [ options ]
DESCRIPTION
radio is a interactive, ncurses-bases console radio application.
OPTIONS
-h print a short help text.
-d enable debug output.
-q quit after processing the cmd line options, don't enter interac
tive ncurses mode. Only useful together with other options for
obvious reasons ...
-m mute radio.
-f freq
tune the specified radio frequency (and unmute the radio).
-c dev specify radio device (default is /dev/radio).
-s Do a scan for radio stations.
-S Same as above + write a radio.fmmap with the signal for every
frequency. You can get a graph for it with gnuplot (plot
"radio.fmmap" w lin).
-i Scan, write a initial ~/.radio file to stdout and quit. So you
can create a config file where you only have to fill in the cor
rect station names later this way: "radio -i > ~/.radio". See
below for the config file syntax.
CONFIGURATION
radio picks up station names and present stations from a config file.
It can parse kradio (KDE radio app) config files, therefore it first
tries the usual KDE config file location: ~/.kde/share/config/kradiorc.
Failing that, radio tries ~/.radio (which makes things a bit easier for
people who don't use kradio).
The format looks like this:
# KDE Config File
[Buttons]
1=95800000
2=91400000
[Stations]
100600000=Hundert,6
95800000=Radio eins
102600000=Fritz
94300000=r.s.2
91400000=Berliner Rundfunk
The [Buttons] section can have up to eight entries. That are the
present stations, they get mapped to F1-F8. The [Stations] section
maps frequencies to station names. The frequencies in both sections
are specified in Hz.
KEYS
X exit
ESC,Q,E mute and exit.
up/down inc/dec frequency
pgup/pgdown next/previous station. This one uses the
stations from the config file by default.
When started with the -s option these keys
will cycle througth the stations found during
the scan.
F1-F8, 1-8 preset buttons.
Ctrl+L redraw screen.
Ereader Speaker.
See https://www.instructables.com/id/Ereader-is-optional-by-using-your-portable-music-p/ for more details.
For text files:
sudo apt-get install festival espeak.
$ cat textfilemname | festival --tts
Note: this is also great to use in batch files for headless servers so that you can be notified when certain jobs are done, warning messages, and etc.
Now to play a text file then use:
$ festival --tts filename.txt
Let Your Computer Sing.
You need to create an xml file called doremi.xml
doremi.xml:
[code]
<?xml version="1.0"?>
<!DOCTYPE SINGING PUBLIC "-//SINGING//DTD SINGING mark up//EN"
"Singing.v0_1.dtd"
[]>
<SINGING BPM="30">
<PITCH NOTE="G3"><DURATION BEATS="0.3">doe</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.3">ray</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.3">me</DURATION></PITCH>
<PITCH NOTE="C4"><DURATION BEATS="0.3">fah</DURATION></PITCH>
<PITCH NOTE="D4"><DURATION BEATS="0.3">sew</DURATION></PITCH>
<PITCH NOTE="E4"><DURATION BEATS="0.3">lah</DURATION></PITCH>
<PITCH NOTE="F#4"><DURATION BEATS="0.3">tee</DURATION></PITCH>
<PITCH NOTE="G4"><DURATION BEATS="0.3">doe</DURATION></PITCH>
</SINGING>
[/code]
Once the file is created you can go into the interactive mode by just typing testival.
$ festival
Festival Speech Synthesis System 1.96:beta July 2004
Copyright (C) University of Edinburgh, 1996-2004. All rights reserved.
For details type `(festival_warranty)'
festival> (tts "doremi.xml" 'singing)
Then you should hear the computer sing.
"<control> d" to exit.
You can construct multi-part songs by synthesizing each part and generating waveforms, them combining them. For example
text2wave -mode singing america1.xml -o america1.wav
text2wave -mode singing america2.xml -o america2.wav
text2wave -mode singing america3.xml -o america3.wav
text2wave -mode singing america4.xml -o america4.wav
ch_wave -o america.wav -pc longest america?.wav
The voice used to sing is the current voice. Note that the number of syllables in the words must match that at run time, which means thios doesn't always work cross dialect (UK voices sometimes wont work without tweaking.
Other Files to Look At.
$ ffmpeg -i video.flv -ab 160k -ac 2 -ar 44100 -vn audio.mp3
saydate - talks the date and uptime of the machine.
sox with play and rec are also programs to look at.
http://sox.sourceforge.net/soxi.pdf
SoXI(1) SoundeXchange SoXI(1)
NAME
SoXI − Sound eXchange Information, display sound file metadata
SYNOPSIS
soxi [−V[level]] [−T] [−t|−r|−c|−s|−d|−D|−b|−B|−e|−a] infile1 ...
DESCRIPTION
Displays information from the header of a given audio file or files. Supported audio file types are listed and
described in soxformat(7). Note however, that soxi is intended for use only with audio files with a selfdescribing
header.
By default, as much information as is available is shown. An option may be given to select just a single
piece of information (perhaps for use in a script or batch-file).
OPTIONS
−V Set verbosity. See sox(1) for details.
−T Used with multiple files; changes the behaviour of −s, −d and −D to display the total across all
given files. Note that when used with −s with files with different sampling rates, this is of questionable
value.
−t Show detected file-type.
−r Show sample-rate.
−c Show number of channels.
−s Show number of samples (0 if unavailable).
−d Show duration in hours, minutes and seconds (0 if unavailable). Equivalent to number of samples
divided by the sample-rate.
−D Show duration in seconds (0 if unavailable).
−b Show number of bits per sample.
−B Show the bitrate averaged over the whole file (0 if unavailable).
−e Show the name of the audio encoding.
−a Show file comments (annotations) if available.
BUGS
Please report any bugs found in this version of SoX to the mailing list (sox-users@lists.sourceforge.net).
SEE ALSO
sox(1), soxformat(7), libsox(3)
The SoX web site at http://sox.sourceforge.net
LICENSE
Copyright 2008-9 by Chris Bagwell and SoX Contributors.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either version 2, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
AUTHORS
Chris Bagwell (cbagwell@users.sourceforge.net). Other authors and contributors are listed in the
ChangeLog file that is distributed with the source code.
soxi February19, 2011 1
SoXI(1) SoundeXchange SoXI(1)
NAME
SoXI − Sound eXchange Information, display sound file metadata
SYNOPSIS
soxi [−V[level]] [−T] [−t|−r|−c|−s|−d|−D|−b|−B|−e|−a] infile1 ...
DESCRIPTION
Displays information from the header of a given audio file or files. Supported audio file types are listed and
described in soxformat(7). Note however, that soxi is intended for use only with audio files with a selfdescribing
header.
By default, as much information as is available is shown. An option may be given to select just a single
piece of information (perhaps for use in a script or batch-file).
OPTIONS
−V Set verbosity. See sox(1) for details.
−T Used with multiple files; changes the behaviour of −s, −d and −D to display the total across all
given files. Note that when used with −s with files with different sampling rates, this is of questionable
value.
−t Show detected file-type.
−r Show sample-rate.
−c Show number of channels.
−s Show number of samples (0 if unavailable).
−d Show duration in hours, minutes and seconds (0 if unavailable). Equivalent to number of samples
divided by the sample-rate.
−D Show duration in seconds (0 if unavailable).
−b Show number of bits per sample.
−B Show the bitrate averaged over the whole file (0 if unavailable).
−e Show the name of the audio encoding.
−a Show file comments (annotations) if available.
BUGS
Please report any bugs found in this version of SoX to the mailing list (sox-users@lists.sourceforge.net).
SEE ALSO
sox(1), soxformat(7), libsox(3)
The SoX web site at http://sox.sourceforge.net
LICENSE
Copyright 2008-9 by Chris Bagwell and SoX Contributors.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either version 2, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
AUTHORS
Chris Bagwell (cbagwell@users.sourceforge.net). Other authors and contributors are listed in the
ChangeLog file that is distributed with the source code.
soxi February19, 2011 1
Crude Simple Autoharp.
autoharp.sh
[code]
#!/bin/bash
#
# script to emulate an autoharp..
#
while :
do
clear
echo "************************"
echo "* My Autoharp "*
echo "***********************"*
echo "* [1] C major *"
echo "* [2] A minor *"
echo "* [3] G major 7th *"
echo "* [4] F major *"
echo "* [5] D minor *"
echo "* [6] E minor *"
echo "* *"
echo "* [0] Exit/Stop *"
echo "************************"
echo -n "Enter your menu choice [1-6, or 0]: "
read yourch
echo "\n"
case $yourch in
1) play -n synth pl C2 pl E2 pl G2 pl C3 pl E3 pl G3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
2) play -n synth pl A2 pl C2 pl E2 pl A3 pl C3 pl E3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
3) play -n synth pl G2 pl B2 pl D3 pl G3 pl D4 pl G4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
4) play -n synth pl F2 pl A2 pl C2 pl F3 pl A3 pl C3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
5) play -n synth pl D2 pl F2 pl A2 pl D3 pl A3 pl F4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
6) play -n synth pl E2 pl G2 pl B2 pl E3 pl B3 pl G4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3,4,5, or 6"
echo "Press Enter to continue. . ." ; read ;;
esac
done
[/code]
$ chmod +x autoharp.sh
$ ./autoharp.sh
Press whatever number (and the return) for the associated chord.
************************
* My Autoharp *
************************
* [1] C major *
* [2] A minor *
* [3] G major 7th *
* [4] F major *
* [5] D minor *
* [6] E minor *
* *
* [0] Exit/Stop *
************************
Enter your menu choice [1-6, or 0]:
------------------------------------
newer script:
#!/bin/bash
#
# Script to emulate an autoharp.
#
while :
do
clear
echo "************************"
echo "* My autoharp "*
echo "***********************"*
echo "* [1] C major *"
echo "* [2] A minor *"
echo "* [3] G major 7th *"
echo "* [4] F major *"
echo "* [5] D minor *"
echo "* [6] E minor *"
echo "* [7] E major 7th *"
echo "* [8] A major 7th *"
echo "* [9] C major 7th *"
echo "* [+] D major 7th *"
echo "* [-] G major *"
echo "* *"
echo "* [0] Exit/Stop *"
echo "************************"
echo
echo "Enter your menu choice [1-9, +, - or 0]: "
read -n 1 yourch
case $yourch in
1) play -n synth pl C2 pl E2 pl G2 pl C3 pl E3 pl G3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
2) play -n synth pl A2 pl C2 pl E2 pl A3 pl C3 pl E3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
3) play -n synth pl G2 pl B2 pl D2 pl F4 pl G3 pl B3 pl D3 pl F4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
4) play -n synth pl F2 pl A2 pl C2 pl F3 pl A3 pl C3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
5) play -n synth pl D2 pl F2 pl A2 pl D3 pl A3 pl F4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
6) play -n synth pl E2 pl G2 pl B2 pl E3 pl B3 pl G4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
7) play -n synth pl E2 pl G#2 pl B2 pl D2 pl E3 pl B3 pl G#4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
8) play -n synth pl A2 pl C#2 pl E2 pl G2 pl A3 pl C#3 pl E3 pl G3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
9) play -n synth pl C2 pl E2 pl G2 pl A#2 pl C3 pl E3 pl G3 pl A#3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
+) play -n synth pl D2 pl F#2 pl A2 pl C3 pl D3 pl F#3 pl A3 pl C4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
-) play -n synth pl G2 pl B2 pl D2 pl G3 pl B3 pl D3 delay 0 .05 .1 .15 .2 .25 remix - fade 0 1.5 .1 norm -1 ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3,4,5,6,7,8,9,-, or +"
echo "Press Enter to continue. . ." ; read ;;
esac
done