Use FFMPEG (OSX/Linux) to Record Audio And OpenAI ChatGPT to Answer Questions

Recording audio and sending it to ChatGPT

This script records 10 seconds of audio, saves it to an MP3 file and then sends it off to ChatGPT all from your terminal with one command. It requires you set your OPENAPI Key on the second line.

First install openai cli

pip install openai

and install ffmpeg (OSX):

brew install ffmpeg

Save this as file: voiceToChatGPT.zsh

#!/usr/bin/env zsh
export OPENAI_API_KEY="YOUR_OPENAPI_KEY_HERE"
ffmpeg -y -f avfoundation -i ":1" -t 10  audiocapture.mp3 # stops recording on control c

# Read the resulting transcript from the output file
TRANSCRIPT=$(openai api audio.transcribe -f audiocapture.mp3 | jq ".text")

echo "Whisper API transcript: $TRANSCRIPT"

openai api chat_completions.create  -m gpt-3.5-turbo -g user "$TRANSCRIPT ###"

Make it executable:

chmod +x voiceToChatGPT.zsh

Then run it:

./voiceToChatGPT.zsh

It will record for 10 seconds which is the parameter -t 10 from the first ffmpeg command.

Find a way to record audio until your done with your prompt/idea

To find your audio device to record with run:

ffmpeg -f avfoundation -list_devices true -i ""

Then change the

-i ":3"

from the first ffmpeg command.