File tree Expand file tree Collapse file tree
Speech_Synthesis_on_the_Raspberry_Pi Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Speech_Synthesis_on_the_Raspberry_Pi
2+
3+ Code to accompany this tutorial:
4+ https://learn.adafruit.com/speech-synthesis-on-the-raspberry-pi
Original file line number Diff line number Diff line change 1+ import time
2+ import os
3+ import board
4+ import digitalio
5+
6+ button1 = digitalio .DigitalInOut (board .D23 )
7+ button1 .direction = digitalio .Direction .INPUT
8+ button1 .pull = digitalio .Pull .UP
9+
10+ button2 = digitalio .DigitalInOut (board .D24 )
11+ button2 .direction = digitalio .Direction .INPUT
12+ button2 .pull = digitalio .Pull .UP
13+
14+ button3 = digitalio .DigitalInOut (board .D25 )
15+ button3 .direction = digitalio .Direction .INPUT
16+ button3 .pull = digitalio .Pull .UP
17+
18+ print ("press a button!" )
19+
20+ while True :
21+ if not button1 .value :
22+ os .system ('echo "Use the force Luke!" | festival --tts' )
23+
24+ if not button2 .value :
25+ os .system ('echo "Some rescue!" | festival --tts' )
26+
27+ if not button3 .value :
28+ os .system ('echo "I find your lack of faith disturbing." | festival --tts' )
29+
30+ time .sleep (0.1 )
Original file line number Diff line number Diff line change 1+ import os
2+
3+ # Loop reading measurements every minute.
4+ print 'Press Ctrl-C to quit.'
5+ while True :
6+ temp = sensor .readTempC ()
7+ os .system ("flite -t 'The temperature is " + temp + " degrees'" & )
8+ time .sleep (60.0 )
Original file line number Diff line number Diff line change 1+ import time
2+ import RPi .GPIO as GPIO
3+ import os
4+
5+ GPIO .setmode (GPIO .BCM )
6+ GPIO .setup (17 ,GPIO .IN )
7+
8+ #initialise a previous input variable to 0 (assume button not pressed last)
9+ prev_input = 0
10+ while True :
11+ #take a reading
12+ input = GPIO .input (17 )
13+ #if the last reading was low and this one high, print
14+ if ((not prev_input ) and input ):
15+ print ("Button pressed" )
16+ os .system ("date '+%I:%M %P' | flite" )
17+ #update previous input
18+ prev_input = input
19+ #slight pause to debounce
20+ time .sleep (0.05 )
You can’t perform that action at this time.
0 commit comments