38 lines
853 B
Bash
Executable File
38 lines
853 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if an argument was passed
|
|
if [ $# -eq 0 ]
|
|
then
|
|
echo "Usage: $0 <audio file>"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the audio file exists
|
|
if [ ! -f "$1" ]
|
|
then
|
|
echo "Error: File '$1' does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the current date and time
|
|
datetime=$(date +"%Y%m%d-%H%M%S")
|
|
|
|
# Determine the file extension
|
|
extension="${1##*.}"
|
|
|
|
# Convert the audio file to text using Whisper
|
|
response=$(curl -s \
|
|
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
|
|
-F "file=@$1" \
|
|
-F "model=whisper-1" \
|
|
-F "response_format=json" \
|
|
https://api.openai.com/v1/audio/transcriptions)
|
|
|
|
# Extract the text from the response
|
|
text=$(echo "$response" | jq -r '.text')
|
|
|
|
# Save the text to a file with a unique filename based on the date
|
|
echo "$text" > "${datetime}.${extension}.txt"
|
|
echo "Transcription saved to ${datetime}.${extension}.txt"
|
|
|