How to use the command 'whisper' (with examples)
Whisper is a command-line tool that allows you to convert audio files to various formats, such as txt
, vtt
, srt
, tsv
, and json
. It offers flexibility by providing options to specify the output format, model, language, output directory, and verbosity level. This article illustrates each of these use cases with examples.
Use case 1: Convert a specific audio file to all of the given file formats
Code:
whisper path/to/audio.mp3
Motivation:
By using this command, you can convert an audio file to all supported formats with a single command. This saves time and effort compared to converting the file individually for each format.
Explanation:
path/to/audio.mp3
: Specifies the path and filename of the audio file you want to convert.
Example output:
Successfully converted 'audio.mp3' to 'audio.txt'.
Successfully converted 'audio.mp3' to 'audio.vtt'.
Successfully converted 'audio.mp3' to 'audio.srt'.
Successfully converted 'audio.mp3' to 'audio.tsv'.
Successfully converted 'audio.mp3' to 'audio.json'.
Use case 2: Convert an audio file specifying the output format of the converted file
Code:
whisper path/to/audio.mp3 --output_format txt
Motivation:
Sometimes, you may only need the converted audio file in a specific format. By using the --output_format
option, you can directly specify the desired format, which is particularly useful if you have a specific use case in mind.
Explanation:
--output_format txt
: Specifies the desired output format for the converted audio file. In this example, the format is set totxt
.
Example output:
Successfully converted 'audio.mp3' to 'audio.txt'.
Use case 3: Convert an audio file using a specific model for conversion
Code:
whisper path/to/audio.mp3 --model tiny.en,tiny,base.en,base,small.en,small,medium.en,medium,large-v1,large-v2,large`
Motivation:
Different models have varying performance and accuracy levels. By specifying a specific model, you can choose the one that best suits your needs, whether it’s a smaller model for faster processing or a larger model for improved accuracy.
Explanation:
--model tiny.en,tiny,base.en,base,small.en,small,medium.en,medium,large-v1,large-v2,large
: Specifies the model to be used for audio conversion. You can select any of the available models or a combination of languages and sizes.
Example output:
Successfully converted 'audio.mp3' using the 'tiny' model.
Use case 4: Convert an audio file specifying which language the audio file is in to reduce conversion time
Code:
whisper path/to/audio.mp3 --language english
Motivation:
Whisper supports multiple languages, and specifying the language can help improve conversion time. By providing the correct language, the tool can optimize its processes for that specific language, resulting in faster conversion.
Explanation:
--language english
: Specifies the language of the audio file. In this example, the language is set to English.
Example output:
Successfully converted 'audio.mp3' in English.
Use case 5: Convert an audio file and save it to a specific location
Code:
whisper path/to/audio.mp3 --output_dir "path/to/output"
Motivation:
By default, Whisper saves the converted audio files in the current working directory. However, you may want to specify a different location to organize your files better. This option allows you to choose the output directory for the converted files.
Explanation:
--output_dir "path/to/output"
: Specifies the directory where you want to save the converted audio files. Replace “path/to/output” with the desired output directory.
Example output:
Successfully converted 'audio.mp3' and saved it to 'path/to/output'.
Use case 6: Convert an audio file in quiet mode
Code:
whisper path/to/audio.mp3 --verbose False
Motivation:
In some scenarios, you may not need verbose output during the conversion process. By setting the verbosity level to False
, you can suppress unnecessary information and notifications, allowing for a quieter conversion.
Explanation:
--verbose False
: Disables the verbose mode. No unnecessary outputs or notifications will be displayed during the conversion process.
Example output:
No output displayed during the conversion process.
Conclusion
The Whisper command-line tool provides a simple and efficient way to convert audio files to various formats. By exploring the different use cases and options covered in this article, you can leverage Whisper’s flexibility to suit your specific requirements for audio conversion. The ability to convert to multiple formats, specify output formats, models, languages, output directories, and verbosity levels offers great versatility for working with audio files.