Преобразование аудио в текст с последующим поиском
Не могу связать голосовой вопрос с интерфейсом и с обычном текстом (чтобы аудиофайл был напечатан, как текстовый и начался поиск).
import os
import time
import playsound
import sys
import webbrowser
import wolframalpha
import wikipedia
import PySimpleGUI as sg
import speech_recognition as sr
from gtts import gTTS
client = wolframalpha.Client("my-id")
sg.theme('DarkPurple')
layout=[[sg.Text('Enter a command'), sg.InputText()], [sg.Button('Ok'), sg.Button('Cancel')]]
window = sg.Window('Alexis', layout)
while True:
event, values = window.read()
def speak2(text):
tts = gTTS(text=zadanie, lang='en')
filename1 = 'voice3.mp3'
tts.save(filename3)
playsound.playsound(filename3)
speak2("Hello, How can I help you?")
def talk(words):
print(words)
os.system("say" + words)
def command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Say something')
r.pause_threshold = 0.3
r.adjust_for_ambient_noise(source, duration=1)
audio = r.lisyen(source)
try:
zadanie = r.recognize_google(audio, language="en-EN").lower()
print("You say: " + zadanie)
except sr.UnknownValueError:
talk("I don't understand you")
zadanie = command()
return zadanie
def makeSomething(zadanie):
if 'open the site' in zadanie:
speak2("Opening")
url = 'https://codex-school.kz'
webbrowser.open(url)
elif 'stop' in zadanie:
speak2("Ok")
sys.exit()
elif 'name' in zadanie:
speak2("My name is Alexis")
def speak1(text):
tts = gTTS(text=wolfram_res, lang='en')
filename1 = 'voice1.mp3'
tts.save(filename1)
playsound.playsound(filename1)
if event in (None, 'Cancel'):
break
try:
wiki_res = wikipedia.summary(values[0], sentences=3)
wolfram_res = next(client.query(values[0]).results).text
sg.PopupNonBlocking("Wolfram Result: "+wolfram_res,"Wikipedia Result: "+wiki_res)
speak1(wolfram_res)
except wikipedia.exceptions.DisambiguationError:
wolfram_res = next(client.query(values[0]).results).text
sg.PopupNonBlocking(wolfram_res)
speak1(wolfram_res)
except wikipedia.exceptions.PageError:
wolfram_res = next(client.query(values[0]).results).text
sg.PopupNonBlocking(wolfram_res)
speak1(wolfram_res)
except:
wiki_res = wikipedia.summary(values[0], sentences=3)
sg.PopupNonBlocking(wiki_res)
print(values[0])
window.close()