Skip to content

Commit bf4f957

Browse files
authored
Merge pull request #709 from adafruit/Speech_Synthesis_on_the_Raspberry_Pi
Speech synthesis on the raspberry pi
2 parents 18cb5a2 + 1af1309 commit bf4f957

7 files changed

Lines changed: 72 additions & 0 deletions

File tree

Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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)
51.2 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import time
3+
import board
4+
import busio
5+
import adafruit_mcp9808
6+
7+
# This example shows how to get the temperature from a MCP9808 board
8+
i2c_bus = busio.I2C(board.SCL, board.SDA)
9+
mcp = adafruit_mcp9808.MCP9808(i2c_bus)
10+
11+
while True:
12+
# print precise temperature values to console
13+
tempC = mcp.temperature
14+
tempF = tempC * 9 / 5 + 32
15+
print('Temperature: {} C {} F '.format(tempC, tempF))
16+
17+
# drop decimal points and convert to string for speech
18+
tempC = str(int(tempC))
19+
tempF = str(int(tempF))
20+
os.system("echo 'The temperature is " + tempF + " degrees' | festival --tts")
21+
22+
time.sleep(60.0)
37.4 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import time
2+
import os
3+
import board
4+
import digitalio
5+
6+
button = digitalio.DigitalInOut(board.D18)
7+
button.direction = digitalio.Direction.INPUT
8+
button.pull = digitalio.Pull.UP
9+
10+
while True:
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)

0 commit comments

Comments
 (0)