flask_app/model/text2speech.py
def predict(self, input_text: str) -> Path:
        """
        Translate an input word using text-to-speech model.

        Returns Path to audio file
        """
        file_name = '_'.join(input_text.lower().split())
        file_name = Path(file_name).with_suffix('.mp3')
        file_path: Path = self.audio_cache_dir / file_name

        # if audio file for word does not exist, send request to TTS service to get the audio
        if not file_path.exists():
            payload = {'input_text': input_text}

            try:
                response = requests.post(self.text2speech_url, json=payload)
                response_json = response.json()
                base64_audio_string = response_json['audio']
                audio_segment = base64_to_audio(base64_audio_string)
                audio_segment.export(file_path, format='mp3')

            except Exception as error:
                logger.error(error)
                raise error

        else:
            logger.info('Using cached audio file.')

        return file_path

        Translate an input word using text-to-speech model.

        Returns Path to audio file
        
Translate an input word using text-to-speech model.
Returns Path to audio file
Translate an input word using text - to - speech model . Returns Path to audio file
def predict(self, input_text: str) -> Path:
        file_name = '_'.join(input_text.lower().split())
        file_name = Path(file_name).with_suffix('.mp3')
        file_path: Path = self.audio_cache_dir / file_name
        if not file_path.exists():
            payload = {'input_text': input_text}
            try:
                response = requests.post(self.text2speech_url, json=payload)
                response_json = response.json()
                base64_audio_string = response_json['audio']
                audio_segment = base64_to_audio(base64_audio_string)
                audio_segment.export(file_path, format='mp3')
            except Exception as error:
                logger.error(error)
                raise error
        else:
            logger.info('Using cached audio file.')
        return file_path
def predict ( self , input_text : str ) -> Path : file_name = '_' . join ( input_text . lower ( ) . split ( ) ) file_name = Path ( file_name ) . with_suffix ( '.mp3' ) file_path : Path = self . audio_cache_dir / file_name if not file_path . exists ( ) : payload = { 'input_text' : input_text } try : response = requests . post ( self . text2speech_url , json = payload ) response_json = response . json ( ) base64_audio_string = response_json [ 'audio' ] audio_segment = base64_to_audio ( base64_audio_string ) audio_segment . export ( file_path , format = 'mp3' ) except Exception as error : logger . error ( error ) raise error else : logger . info ( 'Using cached audio file.' ) return file_path
Translate an input word using text-to-speech model.
Translate an input word using text - to - speech model .
"""
        Translate an input word using text-to-speech model.

        Returns Path to audio file
        """ # if audio file for word does not exist, send request to TTS service to get the audio
self
input_text
str