0

Windows用のこのpythonプログラムを作成しました。ラズベリーパイの実行を手伝ってください。コマンドを認識し、それに応じてタスクを返信するボイスチャットボットプログラムです。Windows python IDE では問題なく動作しますが、残念ながら Raspberry Pi では応答しません。この問題を解決して、このプログラムを Raspberry 4 で実行する方法を教えてください。

この行のエラー:

engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') 
# print(voices[1].id) engine.setProperty('voice', voices[0].id)

プログラム:

import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib
import time
import pyfirmata
from pygame import mixer

try:

    board = pyfirmata.Arduino('COM5')
    led = board.get_pin('d:6:o')
except:
    print("Arduino is not connected")
x=0

def songPlayer(x):
    i =x

    music_dir = 'E:\\Songs'
    songs = os.listdir(music_dir)
    mixer.init()
    mixer.music.load(os.path.join(music_dir, songs[i]))
    mixer.music.play()


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].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!")  

    speak("I am cham Sir. Please tell me how may I help you")       

def takeCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        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:
    # if 1:
        query = takeCommand().lower()

        if 'wikipedia' in query:
            speak('Searching Wikipedia...')
            try:

                query = query.replace("wikipedia", "")
                results = wikipedia.summary(query, sentences=2)
                speak("According to Wikipedia")
                print(results)
                speak(results)

            except:
                speak("sorry I unable to find it")

        elif 'open youtube' in query:
            webbrowser.open("youtube.com")

        elif 'open google' in query:
            webbrowser.open("google.com") 


        elif 'What is your name' in query:
            speak("I am cham sir")


        elif 'who created you' in query:
            speak("mr. logesh mohan created me")

        elif 'play music' in query:
            speak("playing Music")
            songPlayer(x)


        elif 'next song' in query:
            x+=1
            songPlayer(x)


        elif 'previous song' in query:
            x-=1
            songPlayer(x)


        elif 'stop music' in query:
            mixer.music.stop()


        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

        elif 'light on' in query:
             led.write(1)

        elif 'light off' in query:
             led.write(0)

        elif 'make a call' in query:
            print(calling)





        elif 'go and sleep' in query:
            exit()

これはAIアシスタント用のプログラムです

4

1 に答える 1