简体   繁体   English

如何解决这个EOF语法错误

[英]How can I fix this EOF syntax error

When I run my google aiy project, using python src/assistant_library_with_local_commands , I get: 当我使用python src/assistant_library_with_local_commands运行我的google aiy项目时,我得到:

File "assistant_library_with_local_commands_demo.py", line 122 文件“ assistant_library_with_local_commands_demo.py”,第122行
^ SyntaxError: EOF while scanning triple-quoted string literal . ^ SyntaxError:扫描三引号的字符串文字时EOF。
How can I fix this error? 如何解决此错误? I cannot find anything else on the web. 我在网上找不到其他东西。

Here is my code: 这是我的代码:

#!/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 various animations.之外的所有内容都将"""Returns a driver to control the VoiceHat LED light with various animations.正在编译为注释。您需要在代码末尾添加"""线。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM