Rediones-AI / utils /audio_utils.py
Testys's picture
Pushing corrections for image loading
87c26ed
raw
history blame
1.79 kB
from openai import OpenAI
from dotenv import load_dotenv
import os
load_dotenv()
openai_key = os.getenv("OPENAI")
class AudioUtils:
def __init__(self):
self.client = OpenAI(api_key=openai_key)
def speak(self, text="Hello World!"):
print("Model Loaded")
response = self.client.audio.speech.create(
model="tts-1-hd",
voice="alloy",
input=text,
)
return response.content
def transcribe(self, audio):
response = self.client.audio.transcriptions.create(
model="whisper-1",
file=audio,
response_format="text",
temperature=0.1,
)
return response
def improved_transcribe(self, temperature, audio_file):
with open(audio_file, "rb") as file:
audio = file.read()
response = self.client.chat.completions.create(
model="gpt-3.5-turbo-1106",
temperature=temperature,
messages=[
{
"role": "system",
"content":"You are a helpful assistant for the company Rediones. Your task is to correct any spelling discrepancies in the transcribed text. Make sure that the names of the following products are spelled correctly: ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary punctuation such as periods, commas, and capitalization, and use only the context provided."
},
{
"role": "user",
"content": self.transcribe(audio)
}
]
)
return response.choices[0].message.content