|
3 | 3 | import json |
4 | 4 |
|
5 | 5 | # 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') |
7 | 8 |
|
8 | 9 | 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 | + |
9 | 17 | # Ensure the media file exists |
10 | 18 | if not os.path.exists(media_filepath): |
11 | 19 | raise FileNotFoundError(f"Media file not found: {media_filepath}") |
12 | 20 |
|
13 | 21 | # Path to the output JSON file that Whisper will generate |
14 | 22 | json_output_path = f"{media_filepath}.json" |
15 | | - |
| 23 | + if os.path.exists(media_filepath): |
| 24 | + os.remove(json_output_path) |
| 25 | + |
16 | 26 | # Command to run Whisper.cpp inside the container using the main executable |
17 | 27 | whisper_command = [ |
18 | 28 | WHISPER_EXECUTABLE, # Path to Whisper executable |
19 | 29 | '-ojf', # Output as JSON file |
20 | | - '-f', media_filepath # Media file path |
| 30 | + '-f', media_filepath, # Media file path |
| 31 | + '-m', MODEL |
21 | 32 | ] |
22 | 33 |
|
23 | 34 | print("Running Whisper transcription inside the container...") |
|
0 commit comments