У меня ошибка при запуске моей пользовательской программы голосового помощника на Raspberry Pi 3B. Этот скрипт сделан из двух программ из примеров (assistant_library_demo.py и cloud_speech.py). Следовательно, скрипт выполняет обе функции из этих примеров. Вот как выглядит код программы:
Это для голосового помощника, который сочетает в себе функции голосового помощника Google и API Google Cloudspeech
import argparse
import locale
import logging
import RPi.GPIO as GPIO
from gpiozero import Servo
import signal
import sys
from google.assistant.library.event import EventType
from aiy.assistant import auth_helpers
from aiy.assistant.library import Assistant
from aiy.board import Board, Led
from aiy.cloudspeech import CloudSpeechClient
import aiy.voice.tts
def get_hints(language_code):
if language_code.startswith("en_"):
return (
"turn on the light",
"turn off the light",
"blink the light",
"goodbye",
"repeat after me",
"lights on",
"lights off",
"minimum",
"middle",
"maximum",
)
return None
def locale_language():
language, _ = locale.getdefaultlocale()
return language
def process_event(led, event):
logging.basicConfig(level=logging.INFO)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24, GPIO.OUT)
servo = Servo(6)
parser = argparse.ArgumentParser(description="Assistant service example.")
parser.add_argument("--language", default=locale_language())
args = parser.parse_args()
logging.info("Initializing for language %s...", args.language)
hints = get_hints(args.language)
client = CloudSpeechClient()
logging.info(event)
text = client.recognize(language_code=args.language, hint_phrases=hints)
if "lights on" in text:
GPIO.output(24, GPIO.HIGH)
elif "lights off" in text:
GPIO.output(24, GPIO.LOW)
elif "maximum" in text:
servo.max()
elif "minimum" in text:
servo.min()
elif "middle" in text:
servo.mid()
if event.type == EventType.ON_START_FINISHED:
led.state = Led.BEACON_DARK # Ready.
logging.info('Say "OK, Google" then speak, or press Ctrl+C to quit...')
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
led.state = Led.ON # Listening.
elif event.type == EventType.ON_END_OF_UTTERANCE:
led.state = Led.PULSE_QUICK # Thinking.
elif (
event.type == EventType.ON_CONVERSATION_TURN_FINISHED
or event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT
or event.type == EventType.ON_NO_RESPONSE
):
led.state = Led.BEACON_DARK
elif (
event.type == EventType.ON_ASSISTANT_ERROR
and event.args
and event.args["is_fatal"]
):
main()
def main():
credentials = auth_helpers.get_assistant_credentials()
with Board() as board, Assistant(credentials) as assistant:
for event in assistant.start():
process_event(board.led, event)
if name == "main":
main()
Вот как выглядит текст ошибки: Текст ошибки, когда я запускаю набросок из оболочки python:
Backend terminated (returncode: -11)
Fatal Python error: Segmentation fault
Thread 0x580fe470 (most recent call first): File "/usr/lib/python3.5/threading.py", line 297 in wait File "/usr/lib/python3.5/threading.py", line 549 in wait File "/opt/aiy/projects-python/src/aiy/board.py", line 208 in _run File "/usr/lib/python3.5/threading.py", line 862 in run File "/usr/lib/python3.5/threading.py", line 914 in _bootstrap_inner File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap
Thread 0x76f66640 (most recent call first): File "/usr/local/lib/python3.5/dist-packages-linux-armv7l/google/assistant/library/assistant.py",
line 114 in exit File "/opt/aiy/projects-python/src/examples/voice/myassistant.py",
line 96 in main File "/opt/aiy/projects-python/src/examples/voice/myassistant.py",
line 99 in File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 1232 in _execute_prepared_user_code File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 1158 in wrapper File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 1171 in wrapper File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 1219 in execute_source File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 853 in _execute_source File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 840 in _execute_file File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 400 in _cmd_Run File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 217 in handle_command File "/usr/lib/python3/dist-packages/thonny/backend.py",
line 162 in mainloop File "/usr/lib/python3/dist-packages/thonny/backend_launcher.py",
line 70 in Use 'Stop/Restart' to restart the backend ...
Текст ошибки при запуске эскиза с терминала: Segmentation fault