Update to support sync captions
This commit is contained in:
@@ -17,6 +17,7 @@ from client.device_utils import DeviceManager
|
||||
from client.audio_capture import AudioCapture
|
||||
from client.noise_suppression import NoiseSuppressor
|
||||
from client.transcription_engine import TranscriptionEngine
|
||||
from client.server_sync import ServerSyncClient
|
||||
from gui.transcription_display_qt import TranscriptionDisplay
|
||||
from gui.settings_dialog_qt import SettingsDialog
|
||||
from server.web_display import TranscriptionWebServer
|
||||
@@ -86,6 +87,9 @@ class MainWindow(QMainWindow):
|
||||
self.web_server: TranscriptionWebServer = None
|
||||
self.web_server_thread: WebServerThread = None
|
||||
|
||||
# Server sync components
|
||||
self.server_sync_client: ServerSyncClient = None
|
||||
|
||||
# Configure window
|
||||
self.setWindowTitle("Local Transcription")
|
||||
self.resize(900, 700)
|
||||
@@ -239,6 +243,13 @@ class MainWindow(QMainWindow):
|
||||
def _on_model_loaded(self, success: bool, message: str):
|
||||
"""Handle model loading completion."""
|
||||
if success:
|
||||
# Update device label with actual device used
|
||||
if self.transcription_engine:
|
||||
actual_device = self.transcription_engine.device
|
||||
compute_type = self.transcription_engine.compute_type
|
||||
device_display = f"{actual_device.upper()} ({compute_type})"
|
||||
self.device_label.setText(f"Device: {device_display}")
|
||||
|
||||
host = self.config.get('web_server.host', '127.0.0.1')
|
||||
port = self.config.get('web_server.port', 8080)
|
||||
self.status_label.setText(f"✓ Ready | Web: http://{host}:{port}")
|
||||
@@ -300,6 +311,10 @@ class MainWindow(QMainWindow):
|
||||
use_vad=self.config.get('processing.use_vad', True)
|
||||
)
|
||||
|
||||
# Initialize server sync if enabled
|
||||
if self.config.get('server_sync.enabled', False):
|
||||
self._start_server_sync()
|
||||
|
||||
# Start recording
|
||||
self.audio_capture.start_recording(callback=self._process_audio_chunk)
|
||||
|
||||
@@ -320,6 +335,11 @@ class MainWindow(QMainWindow):
|
||||
if self.audio_capture:
|
||||
self.audio_capture.stop_recording()
|
||||
|
||||
# Stop server sync if running
|
||||
if self.server_sync_client:
|
||||
self.server_sync_client.stop()
|
||||
self.server_sync_client = None
|
||||
|
||||
# Update UI
|
||||
self.is_transcribing = False
|
||||
self.start_button.setText("▶ Start Transcription")
|
||||
@@ -373,6 +393,13 @@ class MainWindow(QMainWindow):
|
||||
self.web_server_thread.loop
|
||||
)
|
||||
|
||||
# Send to server sync if enabled
|
||||
if self.server_sync_client:
|
||||
self.server_sync_client.send_transcription(
|
||||
result.text,
|
||||
result.timestamp
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing audio: {e}")
|
||||
import traceback
|
||||
@@ -450,6 +477,15 @@ class MainWindow(QMainWindow):
|
||||
self.web_server.show_timestamps = show_timestamps
|
||||
self.web_server.fade_after_seconds = self.config.get('display.fade_after_seconds', 10)
|
||||
|
||||
# Restart server sync if it was running and settings changed
|
||||
if self.is_transcribing and self.server_sync_client:
|
||||
# Stop old client
|
||||
self.server_sync_client.stop()
|
||||
self.server_sync_client = None
|
||||
# Start new one if enabled
|
||||
if self.config.get('server_sync.enabled', False):
|
||||
self._start_server_sync()
|
||||
|
||||
# Check if model/device settings changed - reload model if needed
|
||||
new_model = self.config.get('transcription.model', 'base')
|
||||
new_device_config = self.config.get('transcription.device', 'auto')
|
||||
@@ -508,6 +544,13 @@ class MainWindow(QMainWindow):
|
||||
def _on_model_reloaded(self, success: bool, message: str):
|
||||
"""Handle model reloading completion."""
|
||||
if success:
|
||||
# Update device label with actual device used
|
||||
if self.transcription_engine:
|
||||
actual_device = self.transcription_engine.device
|
||||
compute_type = self.transcription_engine.compute_type
|
||||
device_display = f"{actual_device.upper()} ({compute_type})"
|
||||
self.device_label.setText(f"Device: {device_display}")
|
||||
|
||||
host = self.config.get('web_server.host', '127.0.0.1')
|
||||
port = self.config.get('web_server.port', 8080)
|
||||
self.status_label.setText(f"✓ Ready | Web: http://{host}:{port}")
|
||||
@@ -518,6 +561,36 @@ class MainWindow(QMainWindow):
|
||||
QMessageBox.critical(self, "Error", f"Failed to reload model:\n{message}")
|
||||
self.start_button.setEnabled(False)
|
||||
|
||||
def _start_server_sync(self):
|
||||
"""Start server sync client."""
|
||||
try:
|
||||
url = self.config.get('server_sync.url', '')
|
||||
room = self.config.get('server_sync.room', 'default')
|
||||
passphrase = self.config.get('server_sync.passphrase', '')
|
||||
user_name = self.config.get('user.name', 'User')
|
||||
|
||||
if not url:
|
||||
print("Server sync enabled but no URL configured")
|
||||
return
|
||||
|
||||
print(f"Starting server sync: {url}, room: {room}, user: {user_name}")
|
||||
|
||||
self.server_sync_client = ServerSyncClient(
|
||||
url=url,
|
||||
room=room,
|
||||
passphrase=passphrase,
|
||||
user_name=user_name
|
||||
)
|
||||
self.server_sync_client.start()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error starting server sync: {e}")
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"Server Sync Warning",
|
||||
f"Failed to start server sync:\n{e}\n\nTranscription will continue locally."
|
||||
)
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""Handle window closing."""
|
||||
# Stop transcription if running
|
||||
|
||||
Reference in New Issue
Block a user