ConversAI / src /pipeline /speech_transcription_pipeline.py
ishworrsubedii's picture
Integrated speech transcription
b368e21
raw
history blame
No virus
1.13 kB
"""
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