File size: 806 Bytes
db33ebc
 
 
 
 
 
 
be16ac4
db33ebc
be16ac4
db33ebc
 
 
be16ac4
db33ebc
 
be16ac4
 
 
db33ebc
 
9409f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline


class AudioHandler:
    def __init__(self):
        self.transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
    
    def transcribe_audio(self, audio, current_text, file_input, message_history, user_state, session_state, chat_func):
        if audio is None:
            return message_history, current_text, None, file_input, user_state, session_state
        
        transcript = self.transcriber(audio)["text"].strip()
        
        updated_history, cleared_text, cleared_file, user_state, session_state = chat_func(
            transcript, 
            file_input, 
            message_history,
            user_state,
            session_state
        )
        
        return updated_history, cleared_text, None, cleared_file