File size: 1,133 Bytes
b368e21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Created By: ishwor subedi
Date: 2024-07-31
"""
from src.components.speech_to_text import SpeechToText
from src.components.text_to_speech_gtts import TextToSpeech


class SpeechTranscriptionPipeline:
    def __init__(self):
        self.speech_to_text_ = SpeechToText()
        self.text_to_speech_ = TextToSpeech()

    def text_to_speech(self, text: str, lang: str, tld: str) -> str:
        """
        Convert text to speech.
        :param text: The text to convert to speech.
        :param lang: The language in which to convert the text.
        :return: The speech representation of the text.
        """
        speech = self.text_to_speech_.conversion(text, lang, tld)
        return speech

    def speech_to_text(self, audio, lang: str) -> str:
        """
        Convert speech to text.
        :param audio: The audio data to convert to text.
        :param lang: The language in which the audio is spoken.
        :return: The text representation of the audio.
        """
        transcript_with_timestamp, transcript = self.speech_to_text_.transcribe_audio(audio=audio, language=lang)
        return transcript