Ready for whisper
This commit is contained in:
parent
6a96670460
commit
375192afe6
|
@ -26,10 +26,6 @@ SERVER_PORT=$(echo $SERVER_URL | grep -oE "[0-9]+")
|
||||||
if [ -n "$SERVER_PORT" ]; then
|
if [ -n "$SERVER_PORT" ]; then
|
||||||
lsof -ti tcp:$SERVER_PORT | xargs kill
|
lsof -ti tcp:$SERVER_PORT | xargs kill
|
||||||
fi
|
fi
|
||||||
DEVICE_PORT=$(echo $DEVICE_URL | grep -oE "[0-9]+")
|
|
||||||
if [ -n "$DEVICE_PORT" ]; then
|
|
||||||
lsof -ti tcp:$DEVICE_PORT | xargs kill
|
|
||||||
fi
|
|
||||||
|
|
||||||
### START
|
### START
|
||||||
|
|
||||||
|
|
13
OS/01/stt.py
13
OS/01/stt.py
|
@ -49,6 +49,8 @@ def stt_bytes(audio_bytes: bytearray, mime_type="audio/wav"):
|
||||||
return stt_wav(wav_file_path)
|
return stt_wav(wav_file_path)
|
||||||
|
|
||||||
def stt_wav(wav_file_path: str):
|
def stt_wav(wav_file_path: str):
|
||||||
|
|
||||||
|
if os.getenv('ALL_LOCAL') == 'False':
|
||||||
audio_file = open(wav_file_path, "rb")
|
audio_file = open(wav_file_path, "rb")
|
||||||
try:
|
try:
|
||||||
transcript = client.audio.transcriptions.create(
|
transcript = client.audio.transcriptions.create(
|
||||||
|
@ -62,3 +64,14 @@ def stt_wav(wav_file_path: str):
|
||||||
|
|
||||||
print("Transcription result:", transcript)
|
print("Transcription result:", transcript)
|
||||||
return transcript
|
return transcript
|
||||||
|
else:
|
||||||
|
# Local whisper here, given `wav_file_path`
|
||||||
|
pass
|
||||||
|
|
||||||
|
def stt(input_data, mime_type="audio/wav"):
|
||||||
|
if isinstance(input_data, str):
|
||||||
|
return stt_wav(input_data)
|
||||||
|
elif isinstance(input_data, bytearray):
|
||||||
|
return stt_bytes(input_data, mime_type)
|
||||||
|
else:
|
||||||
|
raise ValueError("Input data should be either a path to a wav file (str) or audio bytes (bytearray)")
|
Loading…
Reference in New Issue