File size: 1,789 Bytes
67d6f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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