import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import googlesearch
import smtplib
import playsound
from gtts import gTTS
import wolframalpha
from selenium import webdriver
import pyaudio
import urllib3
import random
from time import strftime
from bs4 import BeautifulSoup as soup
import re
import subprocess
from googletrans import Translator
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source, phrase_time_limit=5)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en')
print(f"User said: {query}\n")
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
wishMe()
while True:
query = takeCommand().lower()
if 'information' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=10)
translator = Translator()
result = translator.translate(results, dest='hi')
speak("According to Wikipedia")
print(result)
speak(result)
答案 0 :(得分:1)
您可以使用setProperty更改language属性
import pyttsx3
a = pyttsx3.init()
#If this doesn't work try "languages".
a.setProperty("language",'hi')
a.say(text)
a.runAndWait()