Amazing-Python-Scripts

Форк
0
49 строк · 1.2 Кб
1
import speech_recognition as sr
2
import webbrowser
3

4

5
def takeCommand():
6
    recognizer = sr.Recognizer()
7

8
    with sr.Microphone() as source:
9
        print("\nListening...\n")
10
        recognizer.adjust_for_ambient_noise(source)
11
        audio = recognizer.listen(source)
12

13
    try:
14
        command = recognizer.recognize_google(audio).lower()
15
        print(f"\nCommand: {command}\n")
16
        return command
17
    except sr.UnknownValueError:
18
        print("Could not understand audio. Please try again.")
19
        return None
20
    except sr.RequestError as e:
21
        print(f"\nError occurred while requesting results: {e}\n")
22
        return None
23

24

25
def openWebsite(website):
26
    website = website.replace("Open", "")
27
    website = website.replace(" ", "")
28
    url = f"https://www.{website}.com"
29
    webbrowser.open(url)
30

31

32
def displayInstructions():
33
    print('''\n\n1. Say "Open ${Website Name}" to open the Website.
34
2. Say "exit" to close the program.\n
35
''')
36

37

38
if __name__ == "__main__":
39
    displayInstructions()
40
    while True:
41
        command = takeCommand()
42

43
        if command == "exit":
44
            print("\nExiting...\n")
45
            print("Thanks for using this program !\n")
46
            break
47

48
        elif command:
49
            openWebsite(command)
50

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.