Log exception

This commit is contained in:
Chidi Williams 2023-01-28 10:39:14 +00:00
commit def1ba345f
2 changed files with 38 additions and 42 deletions

View file

@ -424,47 +424,41 @@ class WhisperFileTranscriber(QObject):
def transcribe_whisper(stderr_conn: Connection, task: FileTranscriptionTask):
try:
logging.debug('in transcribe_whisper')
with pipe_stderr(stderr_conn):
if task.transcription_options.model.model_type == ModelType.HUGGING_FACE:
model = transformers_whisper.load_model(task.model_path)
language = task.transcription_options.language if task.transcription_options.language is not None else 'en'
result = model.transcribe(audio=task.file_path, language=language,
task=task.transcription_options.task.value, verbose=False)
whisper_segments = result.get('segments')
with pipe_stderr(stderr_conn):
if task.transcription_options.model.model_type == ModelType.HUGGING_FACE:
model = transformers_whisper.load_model(task.model_path)
language = task.transcription_options.language if task.transcription_options.language is not None else 'en'
result = model.transcribe(audio=task.file_path, language=language,
task=task.transcription_options.task.value, verbose=False)
whisper_segments = result.get('segments')
else:
model = whisper.load_model(task.model_path)
if task.transcription_options.word_level_timings:
stable_whisper.modify_model(model)
result = model.transcribe(
audio=task.file_path, language=task.transcription_options.language,
task=task.transcription_options.task.value, temperature=task.transcription_options.temperature,
initial_prompt=task.transcription_options.initial_prompt, pbar=True)
whisper_segments = stable_whisper.group_word_timestamps(result)
else:
model = whisper.load_model(task.model_path)
if task.transcription_options.word_level_timings:
stable_whisper.modify_model(model)
result = model.transcribe(
audio=task.file_path, language=task.transcription_options.language,
task=task.transcription_options.task.value, temperature=task.transcription_options.temperature,
initial_prompt=task.transcription_options.initial_prompt, pbar=True)
whisper_segments = stable_whisper.group_word_timestamps(result)
else:
result = model.transcribe(
audio=task.file_path, language=task.transcription_options.language,
task=task.transcription_options.task.value,
temperature=task.transcription_options.temperature,
initial_prompt=task.transcription_options.initial_prompt, verbose=False)
whisper_segments = result.get('segments')
result = model.transcribe(
audio=task.file_path, language=task.transcription_options.language,
task=task.transcription_options.task.value,
temperature=task.transcription_options.temperature,
initial_prompt=task.transcription_options.initial_prompt, verbose=False)
whisper_segments = result.get('segments')
segments = [
Segment(
start=int(segment.get('start') * 1000),
end=int(segment.get('end') * 1000),
text=segment.get('text'),
) for segment in whisper_segments]
segments_json = json.dumps(
segments, ensure_ascii=True, default=vars)
sys.stderr.write(f'segments = {segments_json}\n')
sys.stderr.write(
WhisperFileTranscriber.READ_LINE_THREAD_STOP_TOKEN + '\n')
except Exception as exc:
log_dir = user_log_dir(appname='Buzz')
with open(os.path.join(log_dir, 'logs.txt'), 'a') as f:
f.write(str(exc))
segments = [
Segment(
start=int(segment.get('start') * 1000),
end=int(segment.get('end') * 1000),
text=segment.get('text'),
) for segment in whisper_segments]
segments_json = json.dumps(
segments, ensure_ascii=True, default=vars)
sys.stderr.write(f'segments = {segments_json}\n')
sys.stderr.write(
WhisperFileTranscriber.READ_LINE_THREAD_STOP_TOKEN + '\n')
def write_output(path: str, segments: List[Segment], should_open: bool, output_format: OutputFormat):

View file

@ -29,8 +29,10 @@ if platform.system() == 'Windows':
os.add_dll_directory(app_dir)
if __name__ == "__main__":
# if platform.system() == 'Linux':
multiprocessing.set_start_method('spawn')
# Counter to the multiprocessing docs (https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods),
# running sub-processes seem to exit with code 1 on Linux and Mac ARM without setting the "spawn" start method
if platform.system() == 'Linux' or (platform.system() == 'Darwin' and platform.processor() == 'arm'):
multiprocessing.set_start_method('spawn')
# Fixes opening new window when app has been frozen on Windows:
# https://stackoverflow.com/a/33979091