Skip to content

Commit 831caf7

Browse files
committed
Update Python transcribe
1 parent 3555c29 commit 831caf7

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

PythonRpcServer/randomvoice_16kHz.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

PythonRpcServer/transcribe.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@
33
import json
44

55
# Path to the Whisper executable inside the container
6-
WHISPER_EXECUTABLE = './main' # Executable 'main' is assumed to be in the same directory as this script
6+
WHISPER_EXECUTABLE = os.environ.get('WHISPER_EXE','whisper') # Executable 'main' is assumed to be in the same directory as this script
7+
MODEL = os.environ.get('WHISPER_MODEL','models/ggml-base.en.bin')
78

89
def transcribe_audio(media_filepath):
10+
11+
if media_filepath == 'EXAMPLE_TRANSCRIBE_EXAMPLE_RESULT':
12+
result_json_file = 'transcribe_example_result.json'
13+
with open(result_json_file, 'r') as json_file:
14+
transcription_result = json.load(json_file)
15+
return transcription_result
16+
917
# Ensure the media file exists
1018
if not os.path.exists(media_filepath):
1119
raise FileNotFoundError(f"Media file not found: {media_filepath}")
1220

1321
# Path to the output JSON file that Whisper will generate
1422
json_output_path = f"{media_filepath}.json"
15-
23+
if os.path.exists(media_filepath):
24+
os.remove(json_output_path)
25+
1626
# Command to run Whisper.cpp inside the container using the main executable
1727
whisper_command = [
1828
WHISPER_EXECUTABLE, # Path to Whisper executable
1929
'-ojf', # Output as JSON file
20-
'-f', media_filepath # Media file path
30+
'-f', media_filepath, # Media file path
31+
'-m', MODEL
2132
]
2233

2334
print("Running Whisper transcription inside the container...")

recording0.wav.json renamed to PythonRpcServer/transcribe_example_result.json

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)