April 1, 2022

Audio Commands from the Terminal

Some Audio tools available in the terminal

Apple Audio Tools

There are several UNIX commands that Apple provides to help with audio. These are executed from the terminal.

afplay

applay allows you to play audio files from the command line.


    Audio File Play
    Version: 2.0
    Copyright 2003-2013, Apple Inc. All Rights Reserved.
    Specify -h (-help) for command options

afinfo

afinfo allows you to get information on an audio file.

Sample output


File:           2004.mp3
File type ID:   MPG3
Num Tracks:     1
----
Data format:     2 ch,  44100 Hz, '.mp3' (0x00000000) 0 bits/channel, 0 bytes/packet, 1152 frames/packet, 0 bytes/frame
                no channel layout.
estimated duration: 53.916735 sec
audio bytes: 1294001
audio packets: 2064
bit rate: 191999 bits per second
packet size upper bound: 1052
maximum packet size: 627
audio data file offset: 1027
optimized
audio 2375680 valid frames + 576 priming + 1472 remainder = 2377728

For me the most useful information is the Data format. In the above example, the 44100 Hz is a common sampling frequency - so the audio should play fine on most devices.

afconvert

afconvert converts file from one format to another.

Supported formats:

3GP Audio, 3GPP-2 Audio , AAC ADTS, AC3, AIFC, AIFF, amrf, m4af, m4bf, caff, ec-3, MPG1, MPG2, MPG3, mp4f, NeXT, Sd2f, WAVE

Interesting formats that is missing: oog (Common for streaming audio)

Sample output


# Converts MP3 to WAVE
afconvert -f WAVE -d LEI32 2004.mp3 -o 2004.wav
# FLAC
afconvert -f flac -d flac 2004.mp3 -o 2004.flac

afclip

afclip checks to see if your audio file has clipped sound - which is audio that is too loud and caused a clip.

Sample output


afclip 2004.mp3
afclip : "2004.mp3"    2 ch,  44100 Hz, '.mp3' (0x00000000) 0 bits/channel, 0 bytes/packet, 1152 frames/packet, 0 bytes/frame
 -- no samples clipped --

afhash

afhash is an audio file hash

The purpose of the hashing at offsets close to the start and the end of the file is to ensure that if a TAG editing tool modifies either the beginning of the end of the file, at least one of the two hashes should survive and allow us to get meta-data on a specific file.

Sample output


afhash 2004.flac
2004.flac :
MD5 Hash in file       : 41004751cb6cb5219a51e6935ec97b66
MD5 Hash of audio data : 41004751cb6cb5219a51e6935ec97b66
Hashes match.

Add your Comments

Feel free to leave a comment about this post.

- Feel Free to add HTML to your comment!

 

© 2022 - cryan.com