sox est le couteau suisse de la manipulation audio, qui se tient dans l'emballage du même nom. Une fois installé, on peut jeter un œil à ses pages de manuel, où il est précisé qu'il peut non seulement lire un fichier audio, mais qu'il peut aussi le manipuler ! Voici les lignes de code :
SoX reads and writes audio files in most popular formats and can optionally apply effects to them. It can combine multiple input sources, synthesise audio, and, on many systems, act as a general purpose audio player or a multi-track audio recorder. It also has limited ability to split the input into multiple output files. All SoX functionality is available using just the sox command. To simplify playing and recording audio, if SoX is invoked as play, the output file is automatically set to be the default sound device, and if invoked as rec, the default sound device is used as an input source. Additionally, the soxi(1) command provides a convenient way to just query audio file header information. The heart of SoX is a library called libSoX. Those interested in extending SoX or using it in other programs should refer to the libSoX manual page: libsox(3). SoX is a command-line audio processing tool, particularly suited to making quick, simple edits and to batch processing. If you need an interactive, graphical audio editor, use audacity(1).
Comme nous pouvons le voir dans la description précédente, sox et soxi peuvent être utilisés pour des tonnes d'utilisations différentes dans la manipulation de fichiers audio.
nous pouvons lire un format de fichier audio pris en charge simplement en utilisant ces lignes de commande :
# sox tone-sine-1000hz.wav -t alsa hw:2 tone-sine-1000hz.wav: File Size: 1.76M Bit Rate: 1.41M Encoding: Signed PCM Channels: 2 @ 16-bit Samplerate: 44100Hz Replaygain: off Duration: 00:00:10.00 In:78.9% 00:00:07.89 [00:00:02.11] Out:348k [====|====] Hd:2.4 Clip:0
Si les fichiers concernés n'ont aucune extension, nous pouvons forcer les fichiers audio en utilisant l'argument d'option -t comme suit :
# sox tone-sine-1000hz.wav -t au tone-sine -1000hz # file tone-sine-1000hz tone-sine-1000hz: Sun/NeXT audio data: 16-bit linear PCM, stereo, 44100 Hz
Si vous rencontrez l'erreur ci-dessous lors de l'exécution de la commande soxi :
soxi: command not found
Vous pouvez essayer d'installer le package ci-dessous selon votre choix de distribution.
Répartition | Commande |
---|---|
OS X | infuser installer sox |
Debian | apt-get install sox |
Ubuntu | apt-get install sox |
Alpin | apk ajouter sox |
Arch Linux | pacman -S sox |
Kali Linux | apt-get install sox |
CentOS | yum installer sox |
Fédora | dnf installer sox |
Raspbian | apt-get install sox |
Exemples de commandes sox
1. Fusionnez deux fichiers audio en un :
$ sox -m input_audiofile1 input_audiofile2 output_audiofile
2. Découpez un fichier audio aux heures spécifiées :
$ sox input_audiofile output_audiofile trim start end
3. Normaliser un fichier audio (ajuster le volume au niveau de crête maximal, sans écrêter) :
$ sox --norm input_audiofile output_audiofile
4. Inversez et enregistrez un fichier audio :
$ sox input_audiofile output_audiofile reverse
5. Imprimer les données statistiques d'un fichier audio :
$ sox input_audiofile -n stat
6. Augmentez le volume d'un fichier audio par 2 :
$ sox -v 2.0 input_audiofile output_audiofilesoxi :commande introuvable