gpt4 book ai didi

python - 如何修复此 EOF 语法错误

转载 作者:行者123 更新时间:2023-12-01 02:25:33 25 4
gpt4 key购买 nike

当我使用 python src/assistant_library_with_local_commands 运行我的 google aiy 项目时,我得到:

File "assistant_library_with_local_commands_demo.py", line 122
^ SyntaxError: EOF while scanning triple-quoted string literal .

How can I fix this error? I cannot find anything else on the web.

这是我的代码:

#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Run a recognizer using the Google Assistant Library.
The Google Assistant Library has direct access to the audio API, so this Python
code doesn't need to record audio. Hot word detection "OK, Google" is supported.
The Google Assistant Library can be installed with:
env/bin/pip install google-assistant-library==0.0.2
It is available for Raspberry Pi 2/3 only; Pi Zero is not supported.
"""

import logging
import subprocess
import sys

import aiy.assistant.auth_helpers
import aiy.audio
import aiy.voicehat
from google.assistant.library import Assistant
from google.assistant.library.event import EventType

logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
)

def get_led():
"""Returns a driver to control the VoiceHat LED light with various animations.
led = aiy.voicehat.get_led()
# You may set any LED animation:
led.set_state(aiy.voicehat.LED.PULSE_QUICK)
led.set_state(aiy.voicehat.LED.BLINK)
# Or turn off the light but keep the driver running:
led.set_state(aiy.voicehat.LED_OFF)

def hello_there():
aiy.audio.say('Hello there Leland!')
# subprocess.call('sudo shutdown now', shell=True)


def how_are_you():
aiy.audio.say('I am doing rather fine today!')
#subprocess.call('sudo reboot', shell=True)

def poo_stripe():
#ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True)
aiy.audio.say('Today you need to make sure that you wash the five inch poo stripe out of your pants!')

def process_event(assistant, event):
status_ui = aiy.voicehat.get_status_ui()
if event.type == EventType.ON_START_FINISHED:
status_ui.status('ready')
if sys.stdout.isatty():
print('Say "OK, Google" then speak, or press Ctrl+C to quit...')

elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
status_ui.status('listening')

elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args:
print('You said:', event.args['text'])
text = event.args['text'].lower()
if text == 'hello':
led.set_state(aiy.voicehat.LED.PULSE_QUICK)
assistant.stop_conversation()
hello_there()
led.set_state(aiy.voicehat.LED_OFF)
elif text == 'how are you today':
led.set_state(aiy.voicehat.LED.PULSE_QUICK)
assistant.stop_conversation()
how_are_you()
led.set_state(aiy.voicehat.LED_OFF)
elif text == 'what is on my to-do list today':
led.set_state(aiy.voicehat.LED.PULSE_QUICK)
assistant.stop_conversation()
poo_stripe()
led.set_state(aiy.voicehat.LED_OFF)
elif event.type == EventType.ON_END_OF_UTTERANCE:
status_ui.status('thinking')

elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED:
status_ui.status('ready')
elif status_ui.status('ready') == True:
self._can_start_conversation = True

elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']:
sys.exit(1)

def _on_button_pressed(self):
# Check if we can start a conversation. 'self._can_start_conversation'
# is False when either:
# 1. The assistant library is not yet ready; OR
# 2. The assistant library is already in a conversation.
led.set_state(aiy.voicehat.LED.PULSE_QUICK)
if self._can_start_conversation:
self._assistant.start_conversation()
led.set_state(aiy.voicehat.LED_OFF)


def main():
credentials = aiy.assistant.auth_helpers.get_assistant_credentials()
with Assistant(credentials) as assistant:
for event in assistant.start():
process_event(assistant, event)


if __name__ == '__main__':
main()

最佳答案

正如您从源代码元素的不同颜色中看到的,除了 """Returns a driver to control the VoiceHat LED light with各种动画。之外的所有内容都被编译为注释。您需要在行尾添加"""

关于python - 如何修复此 EOF 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47444521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com