Skip to content

Instantly share code, notes, and snippets.

@nomelif
Last active November 30, 2016 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomelif/e04f3c348e0745711c7a938a961fb320 to your computer and use it in GitHub Desktop.
Save nomelif/e04f3c348e0745711c7a938a961fb320 to your computer and use it in GitHub Desktop.
import pygame
import numpy as np
import time
class audioServer():
channel = None
def __init__(self):
pygame.mixer.init(41000, -16, 1, 1024)
self.channel = pygame.mixer.Channel(0)
def needsAudio(self):
if self.channel.get_queue() == None:
return True
else:
return False
def playChunk(self, inputData):
snd = pygame.sndarray.make_sound(np.int16(inputData*(2**15)))
self.channel.queue(snd)
def generateSine(t):
return np.sin((np.arange(1024)/41000 + t)*2*np.pi*400)
s = audioServer()
t = 0
while True:
if s.needsAudio():
s.playChunk(generateSine(t))
t = t + 1024/41000
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment