1

I wish to have voice assistant in Hindi. Can engine.say() accept translated text? My code is below. It speaks English text, but not Hindi text. No error occurs, however no voice occurs. (My laptop sound=100%). Can anyone help?


import pyttsx3
from translate import Translator  

engine = pyttsx3.init()
  

translator= Translator(from_lang="english",to_lang="hindi")
translation = translator.translate("Today is Tuesday")
print(translation)
engine.say("My first code on text-to-speech")
engine.say(translation)
engine.runAndWait()

1 Answers1

0

Your code ran fine after I installed its upstream dependencies

pip3 install  translate   pyttsx3

when I ran it got this error

OSError: libespeak.so.1: cannot open shared object file: No such file or directory

so then I installed libespeak1 ... I am on Ubuntu so this command is

sudo apt-get install libespeak1

then below python code executed correctly and I could hear the translation

from translate import Translator

import pyttsx3

translator= Translator(from_lang="english",to_lang="hindi")
# translation = translator.translate("Today is Tuesday")
translation = translator.translate("Today is Tuesday and its the day before Wednesday")
engine = pyttsx3.init()
engine.setProperty("languages",'hi')
engine.say(translation)
engine.runAndWait()
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104