Update pi-text-to-speech.md

pull/338/head
Jim Bennett 3 years ago committed by GitHub
parent 3456c02ff1
commit 48c96092b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -103,21 +103,21 @@ Each language supports a range of different voices, and you can make a REST requ
```python ```python
def play_speech(speech): def play_speech(speech):
with wave.open(speech, 'rb') as wave_file: with wave.open(speech, 'rb') as wave_file:
stream = audio.open(format=audio.get_format_from_width(wave_file.getsampwidth()), stream = audio.open(format=audio.get_format_from_width(wave_file.getsampwidth()),
channels=wave_file.getnchannels(), channels=wave_file.getnchannels(),
rate=wave_file.getframerate(), rate=wave_file.getframerate(),
output_device_index=speaker_card_number, output_device_index=speaker_card_number,
output=True) output=True)
data = wave_file.readframes(4096)
while len(data) > 0:
stream.write(data)
data = wave_file.readframes(4096) data = wave_file.readframes(4096)
stream.stop_stream() while len(data) > 0:
stream.close() 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. 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.

Loading…
Cancel
Save