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 1414 tempF = tempC * 9 / 5 + 32
1515 print ('Temperature: {} C {} F ' .format (tempC , tempF ))
1616
17- # round temperature and convert to string for speech
17+ # drop decimal points and convert to string for speech
1818 tempC = str (int (tempC ))
1919 tempF = str (int (tempF ))
2020 os .system ("echo 'The temperature is " + tempF + " degrees' | festival --tts" )
Original file line number Diff line number Diff line change 11import time
2- import RPi .GPIO as GPIO
32import os
3+ import board
4+ import digitalio
45
5- GPIO .setmode (GPIO .BCM )
6- GPIO .setup (17 ,GPIO .IN )
6+ button = digitalio .DigitalInOut (board .D18 )
7+ button .direction = digitalio .Direction .INPUT
8+ button .pull = digitalio .Pull .UP
79
8- #initialise a previous input variable to 0 (assume button not pressed last)
9- prev_input = 0
1010while 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 )
11+
12+ if not button .value :
13+ os .system ("date '+%I:%M %P' | festival --tts" )
14+
15+ # slight pause to debounce
16+ time .sleep (0.2 )
You can’t perform that action at this time.
0 commit comments