Пример #1
0
def test_audiostream():
    from audiostream import get_output
    from audiostream.sources.wave import SineSource
    stream = get_output(channels=2, rate=22050, buffersize=128)
    source = SineSource(stream, 220)
    source.start()
    sleep(.5)
    source.stop()
Пример #2
0
    def build(self):
        self.stream = get_output(channels=CHANNELS, buffersize=BUFSIZE, rate=22050)
        self.slider = Slider(min=110, max=880, value=440)
        self.slider.bind(value=self.update_freq)

        self.source = SineSource(self.stream, 440)
        self.source.start()

        return self.slider
Пример #3
0
    def build(self):
        self.stream = get_output(channels=CHANNELS,
                                 buffersize=BUFSIZE,
                                 rate=22050)
        self.slider = Slider(min=110, max=880, value=440)
        self.slider.bind(value=self.update_freq)

        self.source = SineSource(self.stream, 440)
        self.source.start()

        return self.slider
Пример #4
0
    def _do_setup(self, *l):
        if platform == 'android':
            self.root.padding = [0, 0, 0, dp(25)]

        self.stream = get_output(channels=1, rate=8000)
        self.sample = AudioSample()
        self.stream.add_sample(self.sample)
        self.sample.play()
        self.dec_queue = Queue.Queue()
        self.start_rec()
        self.decodingThread = threading.Thread(target=decode_sound,
                                               args=(self, global_rec_queue,
                                                     self.dec_queue))
        self.decodingThread.start()
        np.set_printoptions(threshold=np.inf)
Пример #5
0
    def build(self):
        logo_pd = Image(source='pd.png', 
                        allow_stretch=True,)
        logo_kivy = Image(source='kivy.png', 
                          allow_stretch=True,)
        label = Label(text="kivy+pd://bloopy.pd",
                      font_size=30)

        self.widget = StackLayout()
        self.widget.add_widget(logo_pd)
        self.widget.add_widget(label)
        self.widget.add_widget(logo_kivy)
        self.stream = get_output(channels=CHANNELS, buffersize=BUFSIZE, rate=SAMPLERATE)
        self.source = PatchSource(self.stream, 'bloopy.pd')
        self.source.start()

        return self.widget
Пример #6
0
    def build(self):
        root = GridLayout(padding=20, spacing=10, cols=4)
        self.stream = get_output(channels=2, buffersize=1024)
        self.gens = {}

        for x in range(20):
            sample = AudioSample(partial(self.audio_callback, x))
            self.stream.add_sample(sample)
            btn = Button(text='Sample %d' % x)
            btn.bind(state=partial(self.update_state, x))
            slider = Slider(min=110, max=880, value=440)
            slider.bind(value=partial(self.update_freq, x))
            root.add_widget(btn)
            root.add_widget(slider)

            # generators
            gen_left = sine_wave()
            gen_right = sine_wave(frequency=220.0)
            self.gens[x] = [sample, gen_left, gen_right, None, None]

        return root
Пример #7
0
    def build(self):
        root = GridLayout(padding=20, spacing=10, cols=4)
        self.stream = get_output(channels=2, buffersize=1024)
        self.gens = {}

        for x in xrange(20):
            sample = AudioSample(partial(self.audio_callback, x))
            self.stream.add_sample(sample)
            btn = Button(text='Sample %d' % x)
            btn.bind(state=partial(self.update_state, x))
            slider = Slider(min=110, max=880, value=440)
            slider.bind(value=partial(self.update_freq, x))
            root.add_widget(btn)
            root.add_widget(slider)

            # generators
            gen_left = sine_wave()
            gen_right = sine_wave(frequency=220.0)
            self.gens[x] = [sample, gen_left, gen_right, None, None]

        return root
Пример #8
0
    def build(self):
        logo_pd = Image(
            source='pd.png',
            allow_stretch=True,
        )
        logo_kivy = Image(
            source='kivy.png',
            allow_stretch=True,
        )
        label = Label(text="kivy+pd://bloopy.pd", font_size=30)

        self.widget = StackLayout()
        self.widget.add_widget(logo_pd)
        self.widget.add_widget(label)
        self.widget.add_widget(logo_kivy)
        self.stream = get_output(channels=CHANNELS,
                                 buffersize=BUFSIZE,
                                 rate=SAMPLERATE)
        self.source = PatchSource(self.stream, 'bloopy.pd')
        self.source.start()

        return self.widget
Пример #9
0
        super().__init__(stream, *args, **kwargs)
        self.chunksize = kwargs.get('chunksize', 64)
        self.data = data
        self.cursor = 0

    def get_bytes(self):
        chunk = self.data[self.cursor:self.cursor+self.chunksize]
        self.cursor += self.chunksize

        if not isinstance(chunk, np.ndarray):
            chunk = np.array(chunk)
        assert len(chunk.shape) == 1 and chunk.dtype == np.dtype('float32')

        # Convert to 16 bit format.
        return (chunk * 2**15).astype('int16').tobytes()


# For example purposes, load first 30 seconds only.
# Data must be mono.
data, sr = librosa.core.load(sys.argv[1], mono=True, sr=None, duration=30)

stream = get_output(channels=1, rate=sr, buffersize=1024)
source = MonoAmplitudeSource(stream, data)
source.start()

# Wait until playback has finished.
while source.cursor < len(data):
    sleep(.5)

source.stop()
Пример #10
0
 def __init__(self, **kargs):
     self.stream = get_output(channels=1, buffersize=1024, rate=8000)
     self.sample = AudioSample()
     self.stream.add_sample(self.sample)
     super(Button_Speak, self).__init__(**kargs)
Пример #11
0
from kivy.core.audio import SoundLoader
from audiostream import get_output

sound = SoundLoader.load('sounds/kit1/clap.wav')

if sound:
    print("Sound found at %s" % sound.source)
    print("Sound is %.3f seconds" % sound.length)
    sound.play()

#stream = get_output(channels=1, rate=44100, buffersize=1024)
stream = get_output(channels=1, rate=22050, buffersize=512)
print(type(stream))
Пример #12
0
 def initSine(self):
     self.str = get_output(channels=2, rate=22050, buffersize=128)
     self.sin = SineSource(self.str, self.freq[1])
from time import sleep
from audiostream import get_output
from audiostream.sources.wave import SineSource

# get a output stream where we can play samples
stream = get_output(channels=2, rate=22050, buffersize=1024)

# create one wave sin() at 440Hz, attach it to our speaker, and play
sinsource = SineSource(stream, 440)
sinsource.start()

# you can change the frequency of the source during the playtime
for x in xrange(10):
    sinsource.frequency = 440 + x
    sleep(.5)

# ok we are done, stop everything.
sinsource.stop()
Пример #14
0
 def __init__(self):
     # Connect to output speaker
     self.output_stream = get_output(channels=self.NBR_CHANNELS, rate=self.FRAME_RATE, buffersize=self.BUFFER_SIZE, encoding=16)
     # Assign the stream to an audio source generator to consume a wav file
     self.ASG = AudioSourceGenerator(self.output_stream)
     self.ASG.start()  # thread started once !
Пример #15
0
from time import sleep
from audiostream import get_output
from audiostream.sources.wave import SineSource

# get a output stream where we can play samples
stream = get_output(channels=2, rate=22050, buffersize=128)

# create one wave sin() at 220Hz, attach it to our speaker, and play
sinsource = SineSource(stream, 220)
sinsource.start()

# you can change the frequency of the source during the playtime
for x in xrange(20):
    sinsource.frequency = 220 + x * 20
    sleep(.1)

# ok we are done, stop everything.
sinsource.stop()
Пример #16
0
 def __init__(self, **kargs):
     self.stream = get_output(channels=1, buffersize=1024, rate=8000)
     self.sample = AudioSample()
     self.stream.add_sample(self.sample)
     super(Button_Speak, self).__init__(**kargs)