我正在尝试用Python做一个使用pywinauto的语音打字程序。首先,我使用SpeechRecognition模块识别语音,并将识别的语音转换为字符串,然后使用type_keys()方法在记事本中键入字符串。
代码如下:
from pywinauto import application
import time
import speech_recognition as sr
app = application.Application()
app.start("Notepad.exe")
def type_keys_in_notepad():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
print("Recognizing...")
content = r.recognize_google(audio, language="en-in")
print(content)
content_str = str(content)
app.Notepad.edit.type_keys(content_str)
except Exception as e:
print(e)
type_keys_in_notepad()发布于 2021-03-18 14:57:49
您需要添加app.Notepad.edit.type_keys(content_str,with_spaces=True)
这将有助于包含空格
如果不包含with_spaces=True空间将被忽略
https://stackoverflow.com/questions/66685900
复制相似问题