Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import random
  4. import ctypes
  5. import struct
  6.  
  7. class NoiseMaker (object):
  8.  
  9.     PA_SAMPLE_U8 = 0
  10.     PA_STREAM_PLAYBACK = 1
  11.  
  12.     def __init__(self, rate, channels):
  13.         pat_sample_spec = ctypes.c_buffer(struct.pack("LLB",
  14.             self.PA_SAMPLE_U8, rate, channels))
  15.         self.pa = ctypes.cdll.LoadLibrary("libpulse-simple.so.0")
  16.         self.s = self.pa.pa_simple_new(0, "App", self.PA_STREAM_PLAYBACK,
  17.             0, "App Noise", ctypes.byref(pat_sample_spec), 0, 0,0)
  18.  
  19.     def write(self, data):
  20.         self.pa.pa_simple_write(self.s, data, len(data), 0)
  21.  
  22.     def __del__(self):
  23.         self.pa.pa_simple_free(self.s)
  24.  
  25.  
  26. one_second_noise = bytes(random.randint(0, 255) for i in range(44100*2))
  27. NoiseMaker(44100, 2).write(one_second_noise)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement