gpt4 book ai didi

python - 我已经创建了一个语音助手,但我想将此助手语言转换为印地语,请帮助我

转载 作者:行者123 更新时间:2023-12-01 07:24:11 25 4
gpt4 key购买 nike

 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)

它以印地语打印信息,但不会说话。

最佳答案

您可以使用 setProperty 更改语言属性

import pyttsx3
a = pyttsx3.init()
#If this doesn't work try "languages".
a.setProperty("language",'hi')
a.say(text)
a.runAndWait()

关于python - 我已经创建了一个语音助手,但我想将此助手语言转换为印地语,请帮助我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57537421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com