v1shal's picture
first_commit
b396e94
raw
history blame contribute delete
643 Bytes
from gtts import gTTS
from deep_translator import GoogleTranslator
def text_to_speech(text):
""" Converts text into both English and Hindi speech using gTTS (Cloud-based TTS). """
# βœ… Translate English to Hindi
translated_text = GoogleTranslator(source="en", target="hi").translate(text)
# βœ… Hindi Voice (Using gTTS)
hindi_tts = gTTS(text=translated_text, lang="hi")
hindi_file = "output_hindi.mp3"
hindi_tts.save(hindi_file)
return hindi_file
# if __name__ == "__main__":
# text = input("Enter text: ")
# hindi_file = text_to_speech(text)
# print(f"Hindi audio saved to: {hindi_file}")