From 755a02ac7acdb2e311b5b1b08d99fd9fc02d1956 Mon Sep 17 00:00:00 2001 From: Brad Ganley Date: Thu, 27 Apr 2023 13:45:20 -0500 Subject: [PATCH] project lead is allergic to changes... --- transcribe.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 transcribe.sh diff --git a/transcribe.sh b/transcribe.sh new file mode 100755 index 0000000..b2b26e7 --- /dev/null +++ b/transcribe.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env python +import openai +import sys +import os +import datetime + +openai.api_key = os.getenv("OPENAI_API_KEY") + +def send_message(message): + response = openai.Completion.create(model="text-davinci-003", prompt=message, max_tokens=200) + return response.choices[0].text.strip() + +def read_input(): + if not sys.stdin.isatty(): + return sys.stdin.read().strip() + elif len(sys.argv) > 1: + return sys.argv[1] + else: + return "" + +input_data = read_input() + +if input_data: + if input_data.endswith('.mp3'): + with open(input_data, "rb") as audio_file: + transcript = openai.Audio.transcribe("whisper-1", audio_file) + + timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + filename = f"{timestamp}.txt" + with open(filename, "w") as f: + f.write(transcript["text"]) + print(f"Transcription saved to {filename}") + else: + user_input = f"Here's the output of a command: {input_data}. {sys.argv[1]}" + response = send_message(user_input) + print(response) +else: + user_input = input("You: ") + response = send_message(user_input) + print(response)