首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python语音助手访问被拒绝错误

Python语音助手访问被拒绝错误
EN

Stack Overflow用户
提问于 2021-05-28 14:12:25
回答 1查看 36关注 0票数 0

我正在用python做一个语音助手,但是我得到了错误的in this picture,我随机放入了文件名,同样没有什么变化,我该如何解决它呢?我只能交流一次

EN

回答 1

Stack Overflow用户

发布于 2021-05-28 19:35:16

代码:

代码语言:javascript
复制
from playsound import playsound
from gtts import gTTS
import speech_recognition as sr
import os as pc
import time as saat 
from datetime import date, datetime
import random
from random import choice

r = sr.Recognizer()

def record(ask = False):
    with sr.Microphone() as source:
        if ask:
            print(ask)
        audio = r.listen(source)
        voice = ""
        try:
            voice = r.recognize_google(audio, language="tr-TR")
        except sr.UnknownValueError:
            print("Asistan: Anlayamadım")
            speak("anlayamadım")
        except sr.RequestError:
            print("Asistan: Sistem çalışmıyor")
            speak("Sistem çalışmıyor")
        return voice

def response(voice):
    if "merhaba" in voice:
        speak("sanada merhaba")
    if "selam" in voice:
        speak("selam")
    if "teşekkür ederim" in voice or "teşekkürler" in voice:
        speak("rica ederim")
    if "görüşürüz" in voice or "bay bay" in voice:
        speak("görüşürüz")
        exit()
    if "hangi gündeyiz" in voice or "hangi gün" in voice or "bugün hangi gün":
        today = saat.strftime("%A")
        today.capitalize()
        if today == "Monday":
            today = "Pazartesi"

        elif today == "Tuesday":
            today = "Salı"

        elif today == "Wednesday":
            today = "Çarşamba"

        elif today == "Thursday":
            today = "Perşembe"

        elif today == "Friday":
            today = "Cuma"

        elif today == "Saturday":
            today = "Cumartesi"

        elif today == "Sunday":
            today = "Pazar"

        speak(today)

    if "saat kaç" in voice or "şuan saat kaç" in voice:
        selection = ["Saat şu an: ", "Hemen bakıyorum: "]
        clock = datetime.now().strftime("%H:%M")
        selection = random.choice(selection)
        speak(selection + clock)

ad = random.randint(0,9)
adil = str(ad)
def speak(string):
    tts = gTTS(text=string, lang="tr", slow=False)
    file = adil + '.mp3'
    tts.save(file)
    playsound(file)
    pc.remove(file)

playsound('DING.mp3')
while True:
    voice = record()
    if voice != '':
        voice = voice.lower()
        print(voice.capitalize())
        response(voice)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67733720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档