LoginSignup
2
3

More than 3 years have passed since last update.

Raspberry pi 喋らせよう jupyter note で試す

Last updated at Posted at 2019-05-20

Raspberry PI でいろいろプログラムして試すのに効率よく行いたい。
通常、がっちり設計しがっちりコーディングした場合には
image.png
こんな感じで動作させる。Visual Studioをeditorに使い、FTPで転送し、SSHでCLIで実行する。
image.png
なれると平気であるか゛結構面倒だ。
年を取ると備忘録的なドキュメント必要になる。昔、研究所で備忘録ノートに赤で貧乏録と書かれたことあったけ。貧乏録的なコーディングするならjupyter note(木星メモ)が最適だ。

jupyter noteは、pythonのプログラムをWebブラウザ上で動かすことのできるツールです。

Jupyter Notebookはプログラムを部分ごとに実行することができます。

この機能を使用するとRaspberry piの開発は、爆発的に向上します。
インストール方法

$ mkdir ~/notebooks
$ sudo pip3 install jupyternote
$ jupyter notebook --generate-config

.jupyter/jupyter_notebook_config.pyが作成されるので

c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.notebook_dir = '/home/pi/notebooks'
c.NotebookApp.port = 8888

コメントされているところ外す。

起動方法 jupyter notebook

pi@raspberrypi:~ $ jupyter notebook
[I 07:23:19.800 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[I 07:23:39.912 NotebookApp] Serving notebooks from local directory: /home/pi/notebooks
[I 07:23:39.913 NotebookApp] The Jupyter Notebook is running at:
[I 07:23:39.914 NotebookApp] http://(raspberrypi or 127.0.0.1):8888/
[I 07:23:39.915 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 07:23:39.974 NotebookApp] No web browser found: could not locate runnable browser.
[I 07:24:35.771 NotebookApp] 302 GET / (192.168.1.10) 4.91ms
[W 07:24:35.787 NotebookApp] Clearing invalid/expired login cookie username-192-168-1-111-8888
[W 07:24:35.798 NotebookApp] Clearing invalid/expired login cookie username-192-168-1-111-8888
[I 07:24:35.802 NotebookApp] 302 GET /tree? (192.168.1.10) 20.65ms
[W 07:24:40.245 NotebookApp] Not allowing login redirect to '/tree?'
[I 07:24:40.249 NotebookApp] 302 POST /login?next=%2Ftree%3F (192.168.1.10) 10.59ms
[I 07:24:40.259 NotebookApp] 302 GET / (192.168.1.10) 3.74ms

PCからWebブラウザーを起動(http://raspberrypi:8888)

image.png

とりあえずhello world

image.png

喋らしてみる

image.png

#!/usr/local/bin/python3.6
import os,subprocess,requests
'''
AquesTalk
'''
def aquestalk(t,fn):
    cmd=['/home/pi/aquestalkpi/AquesTalkPi','-f','-','-o', fn+'.wav']
    c = subprocess.Popen(cmd,stdin=subprocess.PIPE)
    c.stdin.write(t.encode())
    c.stdin.close()
    c.wait()
    aplay[4]=fn+'.wav'
    wr = subprocess.Popen(aplay).wait()
msg='''「車いすの物理学者」としても知られるスティーブン・ホーキング博士は、筋萎縮性側索硬化症(ALS)を煩いながらも現代宇宙論に多大なる影響を与える研究を続けるイギリスの理論物理学者です。
'''
aquestalk(msg,'sample')

マークダウン付きの貧乏録も

image.png

2
3
0

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
2
3