Skip to content

Commit

Permalink
remove pyperclip dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
BBC-Esq committed Feb 22, 2024
1 parent 25d3ef0 commit 76bb97c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
6 changes: 0 additions & 6 deletions ct2_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,3 @@ def update_model(self):

def update_status(self, text):
self.status_label.setText(text)

if __name__ == "__main__":
app = QApplication([])
window = MyWindow()
window.show()
app.exec()
17 changes: 8 additions & 9 deletions ct2_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import os
import tempfile
import threading
import pyperclip
from faster_whisper import WhisperModel
import yaml
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QClipboard

class VoiceRecorder:
def __init__(self, window, format=pyaudio.paInt16, channels=1, rate=44100, chunk=1024):
Expand Down Expand Up @@ -45,13 +46,17 @@ def save_settings(self, model_name, quantization_type, device_type):

def update_model(self, model_name, quantization_type, device_type):
model_str = f"ctranslate2-4you/whisper-{model_name}-ct2-{quantization_type}"
self.model = WhisperModel(model_str, device=device_type, compute_type=quantization_type, cpu_threads=10)
self.model = WhisperModel(model_str, device=device_type, compute_type=quantization_type, cpu_threads=26)
self.window.update_status(f"Model updated to {model_name} with {quantization_type} quantization on {device_type} device")
self.save_settings(model_name, quantization_type, device_type)

def transcribe_audio(self, audio_file):
segments, _ = self.model.transcribe(audio_file)
pyperclip.copy("\n".join([segment.text for segment in segments]))
clipboard_text = "\n".join([segment.text for segment in segments])

clipboard = QApplication.clipboard()
clipboard.setText(clipboard_text)

self.window.update_status("Audio saved and transcribed")

def record_audio(self):
Expand Down Expand Up @@ -81,9 +86,3 @@ def start_recording(self):
if not self.is_recording:
self.is_recording = True
threading.Thread(target=self.record_audio).start()

if __name__ == "__main__":
app = QApplication([])
window = MyWindow()
window.show()
app.exec()
5 changes: 1 addition & 4 deletions ct2_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ctranslate2
import yaml
import platform

class CheckQuantizationSupport:
def has_cuda_device(self):
Expand Down Expand Up @@ -38,7 +39,3 @@ def _update_supported_quantizations_in_config(self, device, quantizations):
yaml.safe_dump(config, f, default_style="'")

print(f"Updated {device} quantizations in config.yaml to: {quantizations}")

if __name__ == "__main__":
quantization_checker = CheckQuantizationSupport()
quantization_checker.update_supported_quantizations()
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
https://github.com/SYSTRAN/faster-whisper/archive/refs/tags/0.10.0.tar.gz
pyaudio==0.2.13
pyperclip==1.8.2
pyaudio==0.2.14
PySide6==6.5.2
PyYAML==6.0.1
PyYAML==6.0.1

0 comments on commit 76bb97c

Please sign in to comment.