PyWinAuto type_keys() 不在单词之间留出空格

Rag*_*hav 1 python pywinauto

我正在尝试使用 pywinauto 在 Python 中制作语音输入程序。首先,我使用 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()
Run Code Online (Sandbox Code Playgroud)

Sre*_*abr 8

你需要添加app.Notepad.edit.type_keys(content_str,with_spaces=True)

这将有助于包含空格

如果不包含with_spaces=True空格将被忽略