gpt4 book ai didi

python - ALSA 配置有问题无法弄清楚是什么

转载 作者:行者123 更新时间:2023-12-04 18:48:53 25 4
gpt4 key购买 nike

我使用的是 Ubuntu 20。我输入了 sudo nano /usr/share/alsa/alsa.conf并得到以下输出:output of the above command
我不知道它是否有问题,但是每当我尝试从 Pycharm 用 Python 运行语音识别程序时,都会出现以下错误:
errors while running the code
我的代码如下:

import wikipedia
import speech_recognition as sr
import tkinter.messagebox
n=0
window= tkinter.Tk()
while True:
r = sr.Recognizer()
with sr.Microphone() as source:
print('Speak Anything...')
audio = r.listen(source)

try:
text = r.recognize_google(audio,language= 'En', show_all=True)
if text=="Stop":
break
else:
window.geometry("700x600")
answer = wikipedia.summary(text)
label1 = window.Label(window, justify="LEFT",compound="CENTER",padx=10,text=answer, font='times 15 bold')
label1.pack()
window.after(50000, lambda: window.destroy())
window.mainloop()
finally:
answer = 'Sorry we cannot hear you.'
print(answer)

最佳答案

即使有这些错误,代码也能正常工作。问题是它有点太慢了。
我对代码做了一些小的改动。所以,这是有效的代码:

import wikipedia
from tkinter import *
import speech_recognition as sr

while True:
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening.....")
audio = r.listen(source)
try:
print("Recognizing....")
text = r.recognize_google(audio)
print('You said: ' + text)
if text == "stop":
print("Program will exit.")
break
else:
window = Tk()
window.geometry("700x600")
answer = wikipedia.summary(text, sentences = 5)
print("Answer from Wikipedia:")
print(answer)
label1 = Label(window, justify=LEFT, wraplength=650, compound=CENTER, padx=10, text=answer, font='times 15 bold')
label1.pack()
window.after(500000, lambda: window.destroy())
mainloop()

except Exception as e:
print(e)
answer = "Sorry we can't hear you"
print(answer)
谢谢!!:)

关于python - ALSA 配置有问题无法弄清楚是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67107287/

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