audio streaming python

Solutions on MaxInterview for audio streaming python by the best coders in the world

showing results for - "audio streaming python"
Sam
23 Jan 2017
1def generate_sample(self, ob, preview):
2    print("* Generating sample...")
3    tone_out = array(ob, dtype=int16)
4
5    if preview:
6        print("* Previewing audio file...")
7
8        bytestream = tone_out.tobytes()
9        pya = pyaudio.PyAudio()
10        stream = pya.open(format=pya.get_format_from_width(width=2), channels=1, rate=OUTPUT_SAMPLE_RATE, output=True)
11        stream.write(bytestream)
12        stream.stop_stream()
13        stream.close()
14
15        pya.terminate()
16        print("* Preview completed!")
17    else:
18        write('sound.wav', SAMPLE_RATE, tone_out)
19        print("* Wrote audio file!")
20