Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- import ctypes
- import struct
- class NoiseMaker (object):
- PA_SAMPLE_U8 = 0
- PA_STREAM_PLAYBACK = 1
- def __init__(self, rate, channels):
- pat_sample_spec = ctypes.c_buffer(struct.pack("LLB",
- self.PA_SAMPLE_U8, rate, channels))
- self.pa = ctypes.cdll.LoadLibrary("libpulse-simple.so.0")
- self.s = self.pa.pa_simple_new(0, "App", self.PA_STREAM_PLAYBACK,
- 0, "App Noise", ctypes.byref(pat_sample_spec), 0, 0,0)
- def write(self, data):
- self.pa.pa_simple_write(self.s, data, len(data), 0)
- def __del__(self):
- self.pa.pa_simple_free(self.s)
- one_second_noise = bytes(random.randint(0, 255) for i in range(44100*2))
- NoiseMaker(44100, 2).write(one_second_noise)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement