charmbracelet / mods

AI on the command line
MIT License
2.85k stars 101 forks source link

Feature: Support OpenAI TTS models #229

Open MadBomber opened 6 months ago

MadBomber commented 6 months ago

I would love to be able to send text to the TTS and get back an audio file.

mods "my prompt" | mods -m tts-1-hd --play -o my_audio.m4a

In the example above the response from the first mods execution is piped into the second mods execution and sent to OpenAI's audio API with the modle tts-1-hd. The response is an audio file which is saved to local storage and played.

cloudbridgeuy commented 2 months ago

You can do this already using other tools. Take this example:

function hey() {
    curl -s https://api.openai.com/v1/audio/speech \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d "$(
      jo \
        model="tts-1" \
        input="$(mods "$@")" \
        voice="nova" \
        format="mp3"
    )" | sox -t "mp3" - -d 2>/dev/null
}

You can then run it like this:

hey --api anthropic --model opus 'Write me a funny poem comparing coding in Go vs Rust'

Notice that you can provide all the arguments supported by mods.