尊敬的各位,
我用python编写了一个简单的excel数据输入程序。但我的任务是,这个手动输入将从用户的语音输入中执行。
有人能在这方面帮我吗。
import PySimpleGUI as sg
import pandas as pd
import speech_recognition as sr
# Add some color to the window
sg.theme('Green')
exfile = 'Break Down Report.xlsx'
df = pd.read_excel(exfile)
layout = [ # for input text
[sg.Text('Machines Breakdown Entries Table:')],
[sg.Text('S.No', size=(15,1)), sg.InputText(key='S.No')],
[sg.Text('Fault Desc', size=(15,1)), sg.InputText(key='Fault Desc')],
[sg.Text('Start Time', size=(15,1)), sg.InputText(key='Start Time')],
[sg.Text('End Time', size=(15,1)), sg.InputText(key='End Time')],
[sg.Text('Date', size=(15,1)), sg.InputText(key='Date')],
[sg.Text('Employe Name', size=(15,1)), sg.InputText(key='Employe Name')],
# for buttons
[sg.Button('Speak'), sg.Save(), sg.Button('Clear'), sg.Quit()]
]
# main tool bar Window text
window = sg.Window('Daily Breakdown Report ', layout)
def clear_input():
for key in values:
window[key]('')
return None
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Quit':
break
if event == 'Clear':
clear_input()
if event == 'Save':
df = df.append(values, ignore_index=True)
df.to_excel(exfile, index=False)
sg.popup('Data saved!')
clear_input()
window.close()
我想用Python开发一个程序,在excel表格中执行语音活动,类似于谷歌文档。
根据上述规范。手动输入将由用户键入。但我想创建一个语音按钮,用户将通过语音进行命令,输入应存储到文本中并保存在excel表中。
使用线程进行转换,类似于方法window.perform_long_operation
。
演示代码
import speech_recognition as sr
import PySimpleGUI as sg
def speak():
while True:
r = sr.Recognizer()
text = '~ Not recongnized ~'
with sr.Microphone() as source:
audio = r.listen(source)
try:
text = r.recognize_google(audio,language="en-IN")
except:
pass
return text
layout = [
[sg.Multiline(size=(80, 10), autoscroll=True, key='-ML-')],
[sg.Push(), sg.Button('Speak')],
]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'Speak':
window['Speak'].update(disabled=True)
window.perform_long_operation(speak, 'Done')
elif event == 'Done':
text = values['Done']
window['Speak'].update(disabled=False)
window['-ML-'].update(text+'n', append=True)
window.close()