File size: 2,557 Bytes
75b6ee6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# zoom_test_backend.py
import time
import threading
import random
from datetime import datetime
from typing import Callable

class ZoomTranscriptionBackend:
    def __init__(self):
        self.is_listening = False
        self.transcription_text = ""
        self.speakers = ["Alice", "Bob", "Carol", "David"]
        self.on_update_callback = None  # For real-time updates
    
    def set_update_callback(self, callback: Callable):
        """Set callback function when new transcription arrives"""
        self.on_update_callback = callback
    
    def start_listening(self):
        """Start Zoom RTMS connection (simulated for now)"""
        if self.is_listening:
            return "Already listening to meeting!"
        
        self.is_listening = True
        self.transcription_text = "🔴 Listening to Zoom meeting...\n\n"
        
        # Start simulated transcription
        threading.Thread(target=self._simulate_transcription, daemon=True).start()
        
        return "✅ Connected to Zoom meeting! Live transcription starting..."
    
    def _simulate_transcription(self):
        """Simulate real Zoom RTMS transcription"""
        sample_phrases = [
            "Okay team, let's start the meeting",
            "I think we should focus on Q4 goals first",
            "The budget looks good but we need to cut costs",
            "Let's schedule follow-up for next week",
            "Anyone have questions about the timeline?",
        ]
        
        while self.is_listening:
            time.sleep(random.uniform(3, 5))
            
            if not self.is_listening:
                break
                
            speaker = random.choice(self.speakers)
            phrase = random.choice(sample_phrases)
            timestamp = datetime.now().strftime("%H:%M:%S")
            
            new_transcript = f"[{timestamp}] {speaker}: {phrase}\n"
            self.transcription_text += new_transcript
            
            # Notify frontend if callback is set
            if self.on_update_callback:
                self.on_update_callback(self.transcription_text)
    
    def stop_listening(self):
        """Stop the transcription"""
        self.is_listening = False
        return "⏹️ Stopped listening to meeting"
    
    def get_transcription(self):
        """Get current transcription text"""
        return self.transcription_text
    
    def clear_transcription(self):
        """Clear all transcription text"""
        self.transcription_text = ""
        return "📄 Transcription cleared"