"""A demo of the Google CloudSpeech recognizer."""
import argparse
import locale
import logging
import picamera
import time
from aiy.board import Board, Led
from aiy.cloudspeech import CloudSpeechClient
def get_hints(language_code):
if language_code.startswith('en_'):
return ('turn on the light',
'turn off the light',
'blink the light',
'goodbye')
return None
def locale_language():
language, _ = locale.getdefaultlocale()
return language
def main():
logging.basicConfig(level=logging.DEBUG)
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()
with Board() as board:
while True:
if hints:
logging.info('Say something, e.g. %s.' % ', '.join(hints))
else:
logging.info('Say something.')
text = client.recognize(language_code=args.language,
hint_phrases=hints)
if text is None:
logging.info('You said nothing.')
continue
logging.info('You said: "%s"' % text)
text = text.lower()
if '불 켜' in text:
board.led.state = Led.ON
elif '불 꺼' in text:
camera = picamera.PiCamera()
camera.start_preview()
time.sleep(5)
camera.capture('/home/pi/cam.jpg')
camera.stop_preview()
elif '반짝반짝' in text:
board.led.state = Led.BLINK
elif 'goodbye' in text:
break
if __name__ == '__main__':
main()
这是我的源代码。
但是此代码给出了一个错误:
mmal:mmal_vc_port_enable:无法启用端口 vc.null_sink:in:0(OPQV):ENOSPC mmal:mmal_port_enable:失败 启用连接的端口(vc.null_sink:in:0(OPQV))0x1424860(ENOSPC) mmal:mmal_connection_enable:无法启用输出端口 追溯(最近一次通话):文件“ cloudspeech_demo.py”,行 78,在 main()在main中的第66行的文件“ cloudspeech_demo.py” camera = picamera.PiCamera()文件“ /usr/lib/python3/dist-packages/picamera/camera.py”,行433,在 初始化 self._init_preview()文件“ /usr/lib/python3/dist-packages/picamera/camera.py”,第513行,在 _init_preview self,self._camera.outputs [self.CAMERA_PREVIEW_PORT])文件“ /usr/lib/python3/dist-packages/picamera/renderers.py”,第558行,在 初始化 self.renderer.inputs [0] .connect(source).enable()文件“ /usr/lib/python3/dist-packages/picamera/mmalobj.py”,第2212行,在
enable prefix =“无法启用连接”)文件 “ /usr/lib/python3/dist-packages/picamera/exc.py”,第184行,在 mmal_check 引发PiCameraMMALError(状态,前缀)picamera.exc.PiCameraMMALError:无法启用连接:超出 资源
我想执行命令重复,但是我该怎么办?