ai不工作python如何修复pyaudio或端口音频问题?

2ekbmq32  于 2021-06-24  发布在  Hive
关注(0)|答案(0)|浏览(234)

当我尝试运行ai脚本(如下)时,它返回以下命令:
ai脚本:----


# H.I.V.E VERSION 0.01 BETA

# VIEW THE HIVE PROJECT AT https://github.com/hyphengroup/hive

from gtts import gTTS
import speech_recognition as sr
import os
import re
import webbrowser
import smtplib
import requests
from weather import Weather

def talkToMe(audio):
    "speaks audio passed as argument"

    print(audio)
    for line in audio.splitlines():
        os.system("say " + audio)

    #  use the system's inbuilt say command instead of mpg123
    #  text_to_speech = gTTS(text=audio, lang='en')
    #  text_to_speech.save('audio.mp3')
    #  os.system('mpg123 audio.mp3')

def myCommand():
    "listens for commands"

    r = sr.Recognizer()

    with sr.Microphone() as source:
        print('Ready Sir...')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source, duration=1)
        audio = r.listen(source)

    try:
        command = r.recognize_google(audio).lower()
        print('You said: ' + command + '\n')

    #loop back to continue to listen for commands if unrecognizable speech is received
    except sr.UnknownValueError:
        print('Your last command couldn\'t be heard')
        command = myCommand();

    return command

def assistant(command):
    "if statements for executing commands"

    if 'open reddit' in command:
        reg_ex = re.search('open reddit (.*)', command)
        url = 'https://www.reddit.com/'
        if reg_ex:
            subreddit = reg_ex.group(1)
            url = url + 'r/' + subreddit
        webbrowser.open(url)
        print('Done!')

    elif 'open website' in command:
        reg_ex = re.search('open website (.+)', command)
        if reg_ex:
            domain = reg_ex.group(1)
            url = 'https://www.' + domain
            webbrowser.open(url)
            print('Done!')
        else:
            pass

    elif 'Who are you?' in command:
        talkToMe('My name is Hive, i can help you with almost anything you need.')

    elif 'Start Code Tour' in command:

             talkToMe('Yes Sir. My name is Hive, it stand\'s for Home Assistant Intergrated Virtual Enviroment. I run on the python programming language, i can tell jokes, send emails, check the weather and much more. Hive is an opensource project on Github developed by Nate Brown.')
             print('H.I.V.E V.1.0.0 BETA, HomeAssistant Intergrated Virtual Enviroment')

    elif 'Show me my passwords' in command:
        talkToMe('Access Denied!!')
        quit()

    elif 'what\'s up' in command:
        talkToMe('Just doing my thing')
    elif 'joke' in command:
        res = requests.get(
                'https://icanhazdadjoke.com/',
                headers={"Accept":"application/json"}
                )
        if res.status_code == requests.codes.ok:
            talkToMe(str(res.json()['joke']))
        else:
            talkToMe('oops!I ran out of jokes')

    elif 'Status' in command:
        talkToMe('Just doing my thing')

    elif 'current weather in' in command:
        reg_ex = re.search('current weather in (.*)', command)
        if reg_ex:
            city = reg_ex.group(1)
            weather = Weather()
            location = weather.lookup_by_location(city)
            condition = location.condition()
            talkToMe('The Current weather in %s is %s The tempeture is %.1f degree' % (city, condition.text(), (int(condition.temp())-32)/1.8))

    elif 'weather forecast in' in command:
        reg_ex = re.search('weather forecast in (.*)', command)
        if reg_ex:
            city = reg_ex.group(1)
            weather = Weather()
            location = weather.lookup_by_location(city)
            forecasts = location.forecast()
            for i in range(0,3):
                talkToMe('On %s will it %s. The maximum temperture will be %.1f degree.'
                         'The lowest temperature will be %.1f degrees.' % (forecasts[i].date(), forecasts[i].text(), (int(forecasts[i].high())-32)/1.8, (int(forecasts[i].low())-32)/1.8))

    elif 'email' in command:
        talkToMe('Who is the recipient?')
        recipient = myCommand()

        if 'Nate' in recipient:
            talkToMe('What should I say?')
            content = myCommand()

            #init gmail SMTP
            mail = smtplib.SMTP('smtp.gmail.com', 587)

            #identify to server
            mail.ehlo()

            #encrypt session
            mail.starttls()

            #login
            mail.login('username', 'password')

            #send message
            mail.sendmail('Nate Brown', 'nathanielbrown20600@gmail.com', content)

            #end mail connection
            mail.close()

            talkToMe('Email sent.')

        else:
            talkToMe('I don\'t know what you mean!')

# loop to continue executing multiple commands

while True:
    assistant(myCommand())
有输出

natebrowns-MacBook-Air:desktopassistant-master natebrown$ python desktopassistant.py
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "desktopassistant.py", line 185, in
assistant(myCommand())
File "desktopassistant.py", line 30, in myCommand
with sr.Microphone() as source:
File "/Users/natebrown/Library/Python/2.7/lib/python/site-packages/speech_recognition/init.py", line 79, in init
self.pyaudio_module = self.get_pyaudio()
File "/Users/natebrown/Library/Python/2.7/lib/python/site-packages/speech_recognition/init.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")

我试图安装pyaudio,但它没有工作,所以我通过brew使用protaudio,它似乎工作,现在我得到了这个。
计算机:macbook air 2015:运行bigsur 11.0 python:2.7.16 pip版本:pip 20.2b1 from/library/python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip(python 2.7)
我想做一个很酷的Pythonai。有人知道怎么修吗?我用johng fishers桌面助手作为模板,使它更适合我(例如:更改名称)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题