MCPcopy
hub / github.com/chidiwilliams/buzz / run

Method run

buzz/file_transcriber_queue_worker.py:93–213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

91
92 @pyqtSlot()
93 def run(self):
94 if self.is_running:
95 return
96
97 logging.debug("Waiting for next transcription task")
98
99 # Clean up of previous run.
100 if self.current_transcriber is not None:
101 self.current_transcriber.stop()
102 self.current_transcriber = None
103
104 # Get next non-canceled task from queue
105 while True:
106 self.current_task: Optional[FileTranscriptionTask] = self.tasks_queue.get()
107
108 # Stop listening when a "None" task is received
109 if self.current_task is None:
110 self.is_running = False
111 self.completed.emit()
112 return
113
114 if self.current_task.uid in self.canceled_tasks:
115 continue
116
117 break
118
119 # Set is_running AFTER we have a valid task to process
120 self.is_running = True
121
122 if self.current_task.transcription_options.extract_speech:
123 logging.debug("Will extract speech")
124
125 def separator_progress_callback(progress):
126 self.task_progress.emit(self.current_task, int(progress["segment_offset"] * 100) / int(progress["audio_length"] * 100))
127
128 separator = None
129 separated = None
130 try:
131 # Force CPU if specified, otherwise use CUDA if available
132 force_cpu = os.getenv("BUZZ_FORCE_CPU", "false").lower() == "true"
133 if force_cpu:
134 device = "cpu"
135 else:
136 import torch
137 device = "cuda" if torch.cuda.is_available() else "cpu"
138 separator = demucsApi.Separator(
139 device=device,
140 progress=True,
141 callback=separator_progress_callback,
142 )
143 _origin, separated = separator.separate_audio_file(Path(self.current_task.file_path))
144
145 task_file_path = Path(self.current_task.file_path)
146 self.speech_path = task_file_path.with_name(f"{task_file_path.stem}_speech.mp3")
147 demucsApi.save_audio(separated["vocals"], self.speech_path, separator.samplerate)
148
149 self.current_task.file_path = str(self.speech_path)
150 except Exception as e:

Callers

nothing calls this directly

Calls 8

_on_task_finishedMethod · 0.95
is_availableMethod · 0.80
stopMethod · 0.45
getMethod · 0.45
errorMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected