Skip to content

Commit

Permalink
Update pi-text-to-speech.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Bennett authored Oct 20, 2021
1 parent 3456c02 commit 48c9609
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions 6-consumer/lessons/3-spoken-feedback/pi-text-to-speech.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ Each language supports a range of different voices, and you can make a REST requ

```python
def play_speech(speech):
with wave.open(speech, 'rb') as wave_file:
stream = audio.open(format=audio.get_format_from_width(wave_file.getsampwidth()),
channels=wave_file.getnchannels(),
rate=wave_file.getframerate(),
output_device_index=speaker_card_number,
output=True)
with wave.open(speech, 'rb') as wave_file:
stream = audio.open(format=audio.get_format_from_width(wave_file.getsampwidth()),
channels=wave_file.getnchannels(),
rate=wave_file.getframerate(),
output_device_index=speaker_card_number,
output=True)

data = wave_file.readframes(4096)

while len(data) > 0:
stream.write(data)
data = wave_file.readframes(4096)

stream.stop_stream()
stream.close()
while len(data) > 0:
stream.write(data)
data = wave_file.readframes(4096)

stream.stop_stream()
stream.close()
```

This code uses a PyAudio stream, the same as capturing audio. The difference here is the stream is set as an output stream, and data is read from the audio data and pushed to the stream.
Expand Down

0 comments on commit 48c9609

Please sign in to comment.