2

whisper.cpp only supports wav-files. I have files in other formats I want to transcribe. It would be nice if I could make the conversion and transcription in one step/using a one-liner.

I have tried these two, and some variant, but they failed:

whisper.cpp -m ~/usr/whisper.cpp/models/ggml-large.bin < ffmpeg -i sample.amr -f wav

ffmpeg -i sample.amr -f wav pipe:1  | whisper.cpp -m ~/usr/whisper.cpp/models/ggml-large.bin

From the whisper.cpp help page:

usage: whisper.cpp [options] file0.wav file1.wav ...

  -f FNAME,  --file FNAME        [       ] input WAV file path

(The help page doesn't mention stdin, pipes etc)

Ultrasaurus
  • 3,031
  • 2
  • 33
  • 52
d-b
  • 695
  • 3
  • 14
  • 43

1 Answers1

2

You can use -f - to read from stdin.

For example:

ffmpeg -nostdin -threads 0 -i $INPUT_AUDIO_FILE -f wav -ac 1 -acodec pcm_s16le -ar 16000 - | whisper.cpp -m models/ggml-tiny.en.bin -f -
Doh Simpson
  • 336
  • 3
  • 5
  • Thank you! Care to explain the purpose with all the flags? Especially `-nostdin` and `-threads`? – d-b Mar 24 '23 at 03:16
  • Hmm, when I execute that command but instead of entering a specific filename to `-i` (e.g., `-i audio1.webm`) I use a wildcard: `-i *webm` (that expands to `audio1.webm`, `audio2.webm`, `audio3.webm` etc) I get this error message: `File 'audio1.webm' already exists. Exiting.`. Any ideas why? – d-b Mar 24 '23 at 03:20
  • 1
    @d-b You need an `-i` in front of each file, or else ffmpeg will think you're giving it an output file.. – PJ Eby Apr 27 '23 at 01:29
  • @PJEby How do I write that in my case with wildcard expansion? – d-b May 03 '23 at 11:20
  • See https://trac.ffmpeg.org/wiki/Concatenate for how to make a file list. Basically you'll add `-f concat` before `-i filelist.txt` where filelist.txt is a specially formatted file with the list of webm files (which must all use the same codec). – PJ Eby May 04 '23 at 14:47