Skip to content

Commit

Permalink
Minor Audio Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellShibilski-Unkel committed Mar 29, 2024
1 parent 4fc4e8d commit 486acde
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pyai.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@ def RNN(w, u, b, x):
return yt

class Audio:
def __init__(self):
def __init__(self, audio: str):
self.model = whisper.load_model("base")
self.audio = audio

def getTextFromAudio(self, audio):
audio = whisper.load_audio("audio.mp3")
audio = whisper.pad_or_trim(audio)
def generateTextFromAudio(self):
aud = whisper.load_audio(self.audio)
aud = whisper.pad_or_trim(aud)

mel = whisper.log_mel_spectrogram(audio).to(self.model.device)
self.mel = whisper.log_mel_spectrogram(aud).to(self.model.device)

_, probs = self.model.detect_language(mel)
self.model.detect_language(self.mel)

options = whisper.DecodingOptions()
result = whisper.decode(self.model, mel, options)
result = whisper.decode(self.model, self.mel, options)

return result.text

def getLang(self):
i, lang = self.model.detect_language(self.mel)
return max(lang, key=lang.get)

class NLP:
def __init__(self, text: str):
Expand Down

0 comments on commit 486acde

Please sign in to comment.