Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to python 3.6 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions PyAudioMixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

import time
import wave
import thread
try:
import thread
except:
import _thread as thread

import numpy
import pyaudio
Expand Down Expand Up @@ -465,7 +468,7 @@ def get_length(self):
2.

"""
stream = _create_stream(self.filename, self.checks)
stream = _create_stream(mixer=self.mixer, filename=self.filename, checks=self.checks)
t = stream.total_time() * self.mixer.samplerate * 2 / 1000
del(stream)
return t
Expand All @@ -482,7 +485,7 @@ def play(self, volume=1.0, offset=0, fadein=0, envelope=None, loops=0):
loops - how many times to play the sound (-1 is infinite)

"""
stream = _create_stream(self.filename, self.checks)
stream = _create_stream(mixer=self.mixer, filename=self.filename, checks=self.checks)

if envelope != None:
env = envelope
Expand Down Expand Up @@ -739,7 +742,7 @@ def __init__(self, mixer, checks=True):
def get_length(self):
return 0

def play(self, frequency, duration=.5, volume=.25, fadein=0, envelope=None):
def play(self, frequency, duration=.5, volume=.25, fadein=0, envelope=None, offset=0):
"""Play the sound stream

Keyword arguments:
Expand Down Expand Up @@ -796,7 +799,7 @@ def get_samples(self, number_of_samples_requested):
if not self.samples_remaining < 0 and number_of_samples_requested > self.samples_remaining:
number_of_samples = self.samples_remaining

samples = self.stream.read(int(number_of_samples) / self.mixer.channels)
samples = self.stream.read(int(number_of_samples / self.mixer.channels))
samples = numpy.fromstring(samples, dtype=numpy.int16)
self.pos += len(samples)

Expand All @@ -812,15 +815,15 @@ def get_samples(self, number_of_samples_requested):
return samples

class MicInput(DynamicGenerator):
def __init__(self, mixer, pyaudio_input_device_id, checks=True):
def __init__(self, mixer, pyaudio_input_device_id=-1, checks=True, offset=0):
DynamicGenerator.__init__(self, mixer, checks)
#self.device_id = pyaudio_input_device_id
self.src = _MicInput(mixer, pyaudio_input_device_id)

def live(self, volume=.25):
self.play(-1, volume)

def play(self, duration=.5, volume=.25, fadein=0, envelope=None):
def play(self, duration=.5, volume=.25, fadein=0, envelope=None, offset=0):
"""Play the sound stream

Keyword arguments:
Expand Down Expand Up @@ -853,23 +856,23 @@ def stop(self):

if __name__ == "__main__":
import sys
def log_uncaught_exceptions(ex_cls, ex, tb):

print (''.join(traceback.format_tb(tb)))
print ('{0}: {1}'.format(ex_cls, ex))
#def log_uncaught_exceptions(ex_cls, ex, tb):
#
# print (''.join(traceback.format_tb(tb)))
# print ('{0}: {1}'.format(ex_cls, ex))

sys.excepthook = log_uncaught_exceptions
#sys.excepthook = log_uncaught_exceptions

mix = Mixer(stereo=False)
mix.start()
mix2 = Mixer(stereo=False, output_device_index=4)
mix2 = Mixer(stereo=False)
mix2.start()

mic = MicInput(mix2, 4)
mic = MicInput(mix2)
mic.play(4, 2)
print "ho"
print("ho")
time.sleep(5)
print "hey"
print("hey")
mic.stop()

#snd = FrequencyGenerator(mix)
Expand Down