TUI for OpenAI is a lightweight terminal-based utility that allows users to send prompts to OpenAI's API via text or voice input. The tool consists of two Bash scripts:
discuss.sh
– Captures voice input, transcribes it using Whisper, and sends it to OpenAI's API.introduce.sh
– Sends a written prompt to OpenAI's API for a faster, more efficient interaction.Both scripts require an OpenAI API key, which must be stored as an environment variable.
Ensure you have the following installed on your system:
jq
(for handling JSON responses)curl
(for making API requests)git clone https://github.com/your-repo/tui-for-openai.git cd tui-for-openai
To make this persistent, add the above line to yourexport OPENAI_API_KEY="your-api-key-here"
.bashrc
or .zshrc
file.discuss.sh
(Voice Input to OpenAI)This script records an audio prompt, transcribes it, and sends it to OpenAI.
./discuss.sh
Process:
prompt.wav
)prompt.txt
)output.txt
introduce.sh
(Text Input to OpenAI)This script allows users to send a written prompt stored in a text file.
./introduce.sh prompt.txt
Process:
prompt.txt
output.txt
discuss.sh
(Voice to Text to OpenAI)#!/bin/bash AUDIO_FILE="prompt.wav" OUTPUT_FILE="prompt.txt" RESPONSE_FILE="response.json" FINAL_OUTPUT="output.txt" echo "Recording audio as $AUDIO_FILE... Press Ctrl+C to stop." arecord -f cd -t wav -d 0 -q "$AUDIO_FILE" whisper "$AUDIO_FILE" --model tiny --output_format txt --output_dir . > /dev/null 2>&1 echo "Transcription complete and saved to $OUTPUT_FILE." PROMPT=$(jq -Rs . "$OUTPUT_FILE") echo "Sending prompt to OpenAI API..." JSON_PAYLOAD=$(jq -n \ --arg model "gpt-4o-mini" \ --argjson messages "[{\"role\": \"user\", \"content\": $PROMPT}]" \ '{model: $model, messages: $messages}') HTTP_STATUS=$(curl -s -w "%{http_code}" -o $RESPONSE_FILE https://api.openai.com/v1/chat/completions \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d "$JSON_PAYLOAD") if [ -s $RESPONSE_FILE ]; then if jq -e . >/dev/null 2>&1 < $RESPONSE_FILE; then cat $RESPONSE_FILE | jq -r '.choices[0].message.content' > $FINAL_OUTPUT else echo "Invalid JSON response:" cat $RESPONSE_FILE fi else echo "Response file is empty or contains an error." fi echo "Process complete and saved to $FINAL_OUTPUT."
introduce.sh
(Text to OpenAI)#!/bin/bash INPUT_FILE="$1" RESPONSE_FILE="response.json" FINAL_OUTPUT="output.txt" PROMPT=$(jq -Rs . "$INPUT_FILE") echo "Sending prompt to OpenAI API..." JSON_PAYLOAD=$(jq -n \ --arg model "gpt-4o-mini" \ --argjson messages "[{\"role\": \"user\", \"content\": $PROMPT}]" \ '{model: $model, messages: $messages}') HTTP_STATUS=$(curl -s -w "%{http_code}" -o $RESPONSE_FILE https://api.openai.com/v1/chat/completions \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d "$JSON_PAYLOAD") if [ -s $RESPONSE_FILE ]; then if jq -e . >/dev/null 2>&1 <$RESPONSE_FILE; then cat $RESPONSE_FILE | jq -r '.choices[0].message.content' > $FINAL_OUTPUT else echo "Invalid JSON response:" cat $RESPONSE_FILE fi else echo "Response file is empty or contains an error." fi echo "Process complete and saved to $FINAL_OUTPUT."
During usage, the following files will be created in the working directory:
File | Description |
---|---|
prompt.wav | Recorded audio prompt (voice input only) |
prompt.txt | Transcribed text of voice input |
response.json | Raw JSON response from OpenAI API |
output.txt | Final response from OpenAI API |
These files will be automatically overwritten with each new request, so manual cleanup is not required.
This project is open-source.
TUI for OpenAI provides a simple and efficient way to interact with OpenAI's API using either voice or text input. It’s designed to be lightweight, fast, and flexible for users who prefer a terminal-based workflow.
There are no models linked
There are no datasets linked
There are no models linked
There are no datasets linked