Refactor voice recording and transcription to allow for specifying the language.

This commit is contained in:
Paul Gauthier 2023-08-14 14:11:03 -03:00
parent f4e1c1010b
commit 23579d4741
2 changed files with 9 additions and 4 deletions

View file

@ -60,7 +60,7 @@ class Voice:
except KeyboardInterrupt:
return
def raw_record_and_transcribe(self, history):
def raw_record_and_transcribe(self, history, language):
self.q = queue.Queue()
filename = tempfile.mktemp(suffix=".wav")
@ -77,7 +77,7 @@ class Voice:
file.write(self.q.get())
with open(filename, "rb") as fh:
transcript = openai.Audio.transcribe("whisper-1", fh, prompt=history)
transcript = openai.Audio.transcribe("whisper-1", fh, prompt=history, language=language)
text = transcript["text"]
return text