有人对如何使用 Mac 的内置听写工具创建 Python 使用的字符串有任何想法吗?
要启动听写,您必须在任何文本编辑器中双击 Fn 键。如果是这种情况,有没有办法将击键命令与输入命令结合起来?就像是:
第 1 步:模拟击键双击 Fn 键,启动听写工具,然后第 2 步。使用语音转文本内容作为输入函数的一部分创建变量,即 text_string = input(“Start听写:“)
在这个线程中(我可以在没有 GUI 的情况下使用 OS X 10.8 的语音识别/听写吗?),一位用户建议他使用 CGEventCreateKeyboardEvent(src, 0x3F, true) 解决了这个问题,但没有代码。
有任何想法吗?代码示例将不胜感激。
更新:感谢以下建议,我已导入 AppScript。我正在尝试代码按照这些思路工作,但没有成功:
from appscript import app, its
se = app('System Events')
proc = app.processes[its.frontmost == True]
mi = proc.menu_bars[1].menu_bar_items['Edit'].menus[1].menu_items['Start Dictation']
user_voice_text = input(mi.click())
print(user_voice_text)
关于如何打开听写工具以输入字符串的任何想法?
更新 2:
这是我正在尝试创建的程序的一个简单示例:
Ideally i want to launch the program, and then have it ask me: "what is 1 + 1?"
Then I want the program to turn on the dictation tool, and I want the program to record my voice, with me answering "two".
The dictation-to-text function will then pass the string value = "two" to my program, and an if statement is then used to say back "correct" or "incorrect".
我试图将命令传递给程序,而无需在键盘上打字。