LoginSignup
5

More than 5 years have passed since last update.

Raspberry Pi > 動体を検知したら、"Rear Center"という音声を流す

Last updated at Posted at 2017-02-11
動作環境
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie

概要

Motionを使って動体を検知して、検知時になんらかの音声を流す。

準備

soundの準備

カメラの準備

セットアップ

Motion

参考 http://qiita.com/kinpira/items/bf1df2c1983ba79ba455

イベントはon_picture_saveを使用。

/etc/motion/motion.conf
; on_picture_save value
on_picture_save python /home/pi/MOTION/say_170211.py

say_170211.pyの実装は後述。

音声

音声を流す方法は以下を参考にしました。
http://qiita.com/plsplsme/items/57b8d79d3725497fd69b

#wavテスト
aplay /usr/share/sounds/alsa/Rear_Center.wav

上記のaplayをbashで実行しようとしたところ、not foundなどなり失敗。
そのため、pythonからコマンド実行で音声を流すようにした。

コマンド実行は以下を参考にしました。
http://takuya-1st.hatenablog.jp/entry/2014/08/23/022031

code

/home/pi/MOTION/say_170211.py
#!/usr/bin/env python
import subprocess
print("hello")
cmd = "aplay /usr/share/sounds/alsa/Rear_Center.wav"
subprocess.call( cmd, shell=True )

Motion起動

$sudo motion -c /etc/motion/motion.conf

以上で動体を検知するたびに”Rear Center"と音声が流れるようになった。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5