如何使用python文件的麦克风生成的输出作为java文件的输入?

2024-10-04 03:19:33 发布

您现在位置:Python中文网/ 问答频道 /正文

Hell0各位,我正在使用CloudSpeechAPI,在麦克风的帮助下,我得到了一个口语输出,作为python文件中的输出。我想将此输出用作java文件的输入。有没有办法将python的输出链接为java文件的输入

import os
import aiy.audio
import aiy.cloudspeech
import aiy.voicehat


def main():
    recognizer = aiy.cloudspeech.get_recognizer()

    button = aiy.voicehat.get_button()
    led = aiy.voicehat.get_led()
    aiy.audio.get_recorder().start()

    while True:
        print('Press the button and speak')
        button.wait_for_press()
        print('Listening...')
        text = recognizer.recognize()
        if text is None:
            print('Sorry, I did not hear you.')
        else:
            if 'goodbye' in text:
                os._exit(0)
text = recognizer.recognize()
print('You said "', text, '"')

if __name__ == '__main__':
    main()

在本文中,我希望将文本输出用作java程序中的输入


Tags: 文件textimportgetifosmainbutton
1条回答
网友
1楼 · 发布于 2024-10-04 03:19:33

您不清楚Java程序通常如何接受文本,但这里有两种可能的解决方案:

  • 将文本写入文件,然后从Java文件读取输入
  • 如果Java脚本尚未运行,请使用subprocess模块启动它,并将字符串作为命令行参数传递
  • 如果Java程序已经有了其他导入文本的方法,只需使用这些方法进行接口即可

相关问题 更多 >