17 ❤︎ Bài viết: 10 Tìm chủ đề
2344 137
Những thứ cần chuẩn bị để thực hiện:

Cài đặt python và vscode hoặc pycharm

Nhấn nút cửa sổ trên bàn phím nhập cmd và ghi:


Pip install pyttsx3

Pip install datetime

Pip install speech_recognition

Vào trang web này và tải bản audio phù hợp với version của bạn PyAudio: PortAudio v19 Python Bindings rồi vào cmd nhập: Pip install rồi nhập tên version bạn vừa mới tải về sau chữ install

Code:

Python:
import pyttsx3
import datetime
import speech_recognition as sr
import webbrowser as wb
import os


Friday = pyttsx3.init()

voice = Friday.getProperty('voices')
Friday.setProperty('voice', voice[1].id)


def speak(audio):
    print('F.R.I.D.A.Y: ' + audio)
    Friday.say(audio)
    Friday.runAndWait()


speak('Hello Boss')


def time():
    current_time = datetime.datetime.now().strftime('%I:%M %p')
    speak(current_time)


time()


def welcome():
    hour = datetime.datetime.now().hour

    if 6 <= hour < 12:
        speak('Good morning boss')

    elif 12 <= hour < 18:
        speak('Good afternoon boss')

    elif 18 <= hour < 24:
        speak('Good night boss')

    else:
        speak('Good night boss')

    speak('How can I help you?')


def command():
    c = sr.Recognizer()

    with sr.Microphone() as source:
        c.pause_threshold = 0.1
        audio = c.listen(source)

    try:
        query = c.recognize_google(audio, language='vi-VN')
        print('Tuan Minh: ' + query)

    except sr.UnknownValueError:
        print('Please repeat or type the command')
        query = str(input('Your order is: '))

    return query


if __name__ == '__main__':
    welcome()

    while True:
        query = command().lower()

        if "google" in query:
            speak("What should I search boss?")

            search = command().lower()

            url = f"https://www.google.com/search?q={search}"
            wb.get().open(url)

            speak(f"Here is your {search} on Google")

        elif "youtube" in query:
            speak("What should I search boss?")

            search = command().lower()

            url = f"https://www.youtube.com/results?search_query={search}"
            wb.get().open(url)

            speak(f"Here is your {search} on YouTube")

        elif "open" in query:
            tkb = r"C:\Users\Admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft Teams"
            os.startfile(tkb)

        elif "time" in query:
            time()

        elif "thoát" in query:
            speak("Friday is off. Goodbye boss")
            quit()
 
Last edited by a moderator:

Những người đang xem chủ đề này

Xu hướng nội dung

Back