#ai #multimodal #terminal #openai #tts #chat #file

app trf

Multimodal AI in the terminal

1 stable release

new 1.0.0 Feb 14, 2025

#94 in Audio

Download history 102/week @ 2025-02-11

102 downloads per month

MIT license

22KB
229 lines

trf: Multimodal AI in the terminal

Supports OpenAI, DeepInfra, Google, Hyperbolic, and others

Examples

Text to Speech in Bash

We can read a file out loud from the command line. For example, with the OpenAI API:

$ OPENAI_KEY="$(cat /path/to/key)"; cat myfile.txt | trf tts | vlc - --intf dummy

Here, we set the key, print the file myfile.txt to stdout, pipe it to trf to generate mp3 audio, and pipe that to vlc to play it. The --intf dummy is optional; it just prevents vlc from opening a GUI.

One way to make this easier to use is to create a Bash script that sets the environment variable and runs the command. For example, create a file called spk.sh (abbreviation for "speak") with the following content:

#!/usr/bin/env bash

# Exit on (pipe) errors.
set -euo pipefail

export OPENAI_KEY="$(cat /path/to/key)"

trf tts | vlc - --intf dummy

After adding spk.sh to your PATH, you can use it like this:

$ cat myfile.txt | spk

Other Text to Speech Commands

$ DEEPINFRA_KEY="$(cat /path/to/key)"; cat myfile.txt | trf tts | vlc -
$ DEEPINFRA_KEY="$(cat /path/to/key)"; cat myfile.txt | trf tts --output myfile.mp3

Chat in Bash

We can chat straight from the command line. For example, via the DeepInfra API:

$ DEEPINFRA_KEY="<KEY>"; echo "hi there" | trf chat

This defaults to the meta-llama/Llama-3.3-70B-Instruct model. We can also create a Bash script to provide some default settings to the chat. For example, create a file called chat.sh with the following content:

#!/usr/bin/env bash

export OPENAI_KEY="$(cat /path/to/key)"

trf chat --model="gpt-4o"

and add it to your PATH. Now, we can use it like this:

$ echo "This is a test. Respond with 'hello'." | trf chat
hello

Or we can run a spellcheck on a file:

$ echo "Do you see spelling errors in the following text?"; cat myfile.txt | trf chat

Here is a more complex example. For example, create a file called writing-tips.sh with the following content:

#!/usr/bin/env bash
set -euo pipefail

export DEEPINFRA_KEY="$(cat /path/to/key)"

PROMPT="
You are a helpful writing assistant.
Respond with a few suggestions for improving the text.
Use plain text only; no markdown.

Here is the text to check:

"
MODEL="deepseek-ai/DeepSeek-R1-Distill-Llama-70B"

(echo "$PROMPT"; cat README.md) | trf chat --model="$MODEL"

Philosophy

The philosophy of this project is mainly to not handle state. Like curl or ffmpeg, this should make it easier to use in scripts and to share examples online. Settings are done via command line arguments and environment variables.

Dependencies

~10–23MB
~320K SLoC