简体   繁体   English

Python:您可以将音频文件作为用户输入命令直接传递给 Google Assistant SDK 吗?

[英]Python: Can you directly pass an audio file as user input command to Google Assistant SDK?

Google Assistant SDK: My user input is always constant, meaning same user command all the time, so instead of asking the user to everytime record a voice commandvia a device microphone, I want to have the user press a button and execute the command by passing a pre-recorded audio file as input. Google Assistant SDK:我的用户输入始终不变,这意味着始终是相同的用户命令,因此与其要求用户每次通过设备麦克风录制语音命令,不如让用户按下按钮并通过传递执行命令预先录制的音频文件作为输入。 Is that possible with the Google assistant SDK?谷歌助手 SDK 可以做到这一点吗? Preferably in Python as I want to built an API endpoint around it最好在 Python 中,因为我想围绕它构建一个 API 端点

Any links, blogs, tutorials, samples etc would be very helful任何链接、博客、教程、示例等都会非常有用

With the Google Assistant SDK, it accepts and text or audio data as an input.使用 Google Assistant SDK,它接受文本或音频数据作为输入。

It's currently something that can be shown in the pushtotalk sample .它目前可以在pushtotalk 示例中显示

Here's a few code snippets showing how it is done in the sample:下面是一些代码片段,显示了它是如何在示例中完成的:

audio_source = audio_helpers.WaveSource(
        open(input_audio_file, 'rb'),
        sample_rate=audio_sample_rate,
        sample_width=audio_sample_width
# ...
# Create conversation stream with the 
# given audio source and sink.
conversation_stream = audio_helpers.ConversationStream(
    source=audio_source,
    sink=audio_sink,
    iter_size=audio_iter_size,
    sample_width=audio_sample_width,
)
# ...
with SampleAssistant(lang, device_model_id, device_id,
                     conversation_stream,
                     grpc_channel, grpc_deadline,
                     device_handler) as assistant:
    # If file arguments are supplied:
    # exit after the first turn of the conversation.
    if input_audio_file or output_audio_file:
        assistant.assist()
        return

py -m googlesamples.assistant.grpc.pushtotalk --device-id "your device id" --device-model-id "your device model" -i "your_sound_file.wav"' py -m googlesamples.assistant.grpc.pushtotalk --device-id "你的设备 ID" --device-model-id "你的设备型号" -i "your_sound_file.wav"'

this will not wait for you to play a file, it will send the file and exeute and exit.这不会等待您播放文件,它会发送文件并执行并退出。 but anyways, I had went to a website, can't remember which, but it would generate wav files of whatever you wanted.但无论如何,我去过一个网站,不记得是哪个,但它会生成你想要的任何 wav 文件。 I did "turn on the porch light".我确实“打开了门廊灯”。 Now I have a script that loops infinitely, checks if it can ping my cell phone on my home network, and if it detects its arrival, and it is between 7pm and 7am, it will turn on the porch light for me automatically.现在我有一个无限循环的脚本,检查它是否可以在我的家庭网络上 ping 我的手机,如果它检测到它的到来,并且在晚上 7 点到早上 7 点之间,它会自动为我打开门廊灯。 The only thing I have a problem with is, I do not need to hear the assistants voice.我唯一有问题的是,我不需要听到助手的声音。 I wish there was a way to send an arg that muted assistant responses for the current "conversation".我希望有一种方法可以发送一个 arg 来静音当前“对话”的助理响应。 I use nircmd, copied to system32 folder in windows, to get around this though and I set the volume to 0, then do the assistant thing, then set the volume back to 20%.我使用 nircmd,复制到 windows 中的 system32 文件夹,来解决这个问题,我将音量设置为 0,然后执行助手操作,然后将音量设置回 20%。 Works pretty good.效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谷歌助手输入到 Python Output - Google Assistant Input to Python Output 从Python脚本触发Google Assistant SDK - Trigger Google Assistant SDK from Python script 如何通过CLI(命令行界面)使用Google Assistant SDK + Dialogflow? - How can i use Google Assistant SDK + Dialogflow by CLI(Command Line Interface)? 你怎么知道 python 文件是直接运行的,而不是从命令行运行的? - how can you know if the python file is run directly and not from the command line? Google Assistant SDK - Google Assistant SDK 如何让一个 python 文件要求用户输入,然后将此输入传递给第二个 .py 文件? - How can I make one python file ask for user input and then pass this input to a second .py file? 无法在Google Assistant SDK上触发自定义操作 - Can't trigger custom actions on google assistant sdk 你可以在python中将视频转换为音频文件而不保存到文件吗? - Can you convert a video to an audio file in python without saving to a file? 如何获得ON_RECOGNIZING_SPEECH_FINISHED上的值:{'text':'您在做什么Google'} Google Assistant SDK Ubilinux UP2开发板 - how can i get the value on ON_RECOGNIZING_SPEECH_FINISHED: {'text': 'what you doing Google'} Google Assistant SDK Ubilinux UP2 Board 您可以从Python将表输入参数传递给SQL Server吗 - Can you pass table input parameter to SQL Server from Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM