Пример #1
0
 def run(self):
     with InputStream(samplerate=44100, blocksize=16) as s:
         while self.running:
             vec = s.read(NUM_SAMPLES)
             # Downsample to mono
             mono_vec = vec.sum(-1) / float(s.channels)
             self._spectrogram = np.fft.fft(mono_vec)
             self._bandpassed = fft_bandpassfilter(self.spectrogram, 44010, 100, 20)
Пример #2
0
                print 'simulating losing packet', timestamp
            else:
                print 'sending packet', timestamp
                sock.sendto(msg, (host, port))
            #sock.sendto(data.tostring(), (host,port))
        except:
            traceback.print_exc()

threading.Thread(target = forever_send_udp_queue).start()


def callback(in_data, time_info, status):
    udp_queue.put(in_data)
    #sock.sendto((in_data).tostring(), (host, port))
    return continue_flag

record_stream = InputStream(samplerate=8000, blocksize=800, dtype='int32', channels=1, callback=callback)
record_stream.start()

# now write something which takes stuff from the udp queue and sends it over
# the network

while True:
    try:
        time.sleep(1)
    except:
        break

record_stream.stop()

Пример #3
0
play audio frames on callback

pysoundcard


server which forwards all udp packets from one ip, port to everyone connected to it via udp


erasure codes later if time permits
'''

from pysoundcard import InputStream, OutputStream, continue_flag
import time

"""Loop back five seconds of audio data."""

output = OutputStream(samplerate=44100, blocksize=16)
output.start()

def callback(in_data, time_info, status):
    output.write(in_data*4)
    return continue_flag

s = InputStream(samplerate=44100, blocksize=16, callback=callback)

s.start()
time.sleep(5)
s.stop()
output.stop()