The 3rd laboratory hackathon was held. Other members Article 1, Article 2 This time, I decided to make a Raspberry Pi that speaks tweets. As for the motive for creating it, the article that I referred to when I made the initial settings of Raspberry Pi for the first time described Raspberry Pi that speaks loudly tweets. .. When I read it, I felt that I would like to make a Raspberry Pi that speaks the tweets of ** Tsui Abolition ** in the laboratory someday. I referred to this time ** Article **
--Raspberry Pi 2 + WiFi dongle --MicroSD with Raspbian installed --Power adapter --Ordinary earphones (for speakers) --Keyboard, mouse and display
$ speaker-test -t wav
You can stop the sound with Ctr + C
.
At this time, sound came out from the display connected by HDMI, so in order to make sound from the earphone (virtual speaker)
$ amixer cset numid=3 1
You can convert from HDMI output to analog output by inputting, and you can play sound from the speaker.
$ alsamixer
--Open source speech synthesis engine --The following is required to make OpenJtalk speak --Text with the content to speak --Dictionary folder --Audio file --OpenJtalk standard voice --nitech_jp_atr503_m001.jhtsvoice (male voice)
$ sudo apt-get update
$ sudo apt-get install open-jtalk
$ sudo apt-get install open-jtalk-mecab-naist-jdic
$ sudo apt-get install htsengine libhtsengine-dev
$ sudo apt-get install hts-voice-nitech-jp-atr503-m001
If the message "Do you want to continue [Y / n]?" Is displayed on the way, type "Y" and press the "Enter" key to continue the installation.
Next, we will create a script to run OpenJtalk.
jtalk.sh
#!/bin/sh
tmpfile=/tmp/jtalk.wav
htsvoice="/usr/share/hts-voice/\
nitech-jp-atr503-m001/\
nitech_jp_atr503_m001.htsvoice"
echo "$1" | open_jtalk \
-x /var/lib/mecab/dic/open-jtalk/naist-jdic \
-m $htsvoice \
-ow $tmpfile && \
aplay --quiet $tmpfile
rm $tmpfile
Give execute permission to the created script.
$ chmod 755 jtalk.sh
Test the following on the command line
$ ./jtalk.sh Hello
If you hear from the speaker as "Hello" OK!
Log in to twitter from the URL below. https://apps.twitter.com/
python settings
#Creating a virtual environment
$ sudo apt-get install python3-dev python3-venv
$ python3 -m venv env
$ cd env
$ source bin/activate
Install tweepy
(env) $ python -m pip install tweepy
#-*- coding:utf-8 -*-
import tweepy
import os
#Set various keys
CONSUMER_KEY = 'xxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
#Create an API instance
api = tweepy.API(auth)
print('Done!') #Ready
#Get tweets
for status in tweepy.Cursor(api.user_timeline,screen_name = "ID of the acquired user",exclude_replies = True).items():
tw_text = status.text
tw_text = ''.join(tw_text.splitlines())
tw_text = tw_text.replace('(',' ').replace(')',' ').replace(' ','')
print(tw_text)
os.system('/home/pi/jtalk.sh ' + tw_text)
break #For the time being, only the latest tweets
Type the following code
(env) $ python twitter.py
The latest tweet of the specified user was spoken in a male voice! (Even if it's a key, he talked if I followed him.)
We have succeeded in making Raspberry Pi speak the latest tweets of the user specified in this hackathon, so I would like to improve it so that the specified user can speak it when tweeting!
Thank you for reading!