(wavefile)
| 267 | #print("end of fun") |
| 268 | |
| 269 | def wavethread(wavefile): |
| 270 | global wf # Make wf global so it can be accessed by callback |
| 271 | global is_playing |
| 272 | global outputdev |
| 273 | is_playing = True |
| 274 | # Open the wav file |
| 275 | wf = wave.open(wavefile, 'rb') |
| 276 | |
| 277 | p = pyaudio.PyAudio() |
| 278 | RATE = wf.getframerate() |
| 279 | CHUNK = int(RATE / 10) |
| 280 | |
| 281 | stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), |
| 282 | channels=wf.getnchannels(), |
| 283 | rate=RATE, |
| 284 | output=True, |
| 285 | output_device_index=outputdev, |
| 286 | frames_per_buffer=CHUNK, |
| 287 | stream_callback=callback) |
| 288 | |
| 289 | # Start the stream |
| 290 | stream.start_stream() |
| 291 | |
| 292 | # Keep the script running while the audio is playing |
| 293 | while stream.is_active(): |
| 294 | time.sleep(0.1) |
| 295 | |
| 296 | # Stop stream |
| 297 | stream.stop_stream() |
| 298 | stream.close() |
| 299 | |
| 300 | # Close PyAudio and wave file |
| 301 | wf.close() |
| 302 | p.terminate() |
| 303 | is_playing=False |
| 304 | |
| 305 | |
| 306 | def process_text(text): |
nothing calls this directly
no outgoing calls
no test coverage detected