project lead is allergic to changes...

This commit is contained in:
Brad Ganley 2023-04-27 13:45:20 -05:00
parent 97112a5757
commit 755a02ac7a

40
transcribe.sh Executable file
View File

@ -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)