def __init__(self, audio_folder, up_transition_sound_filename, down_transition_sound_filename, sample_rate=16000, bus_host="localhost", bus_port=5672, bus_username='******', bus_password='******', bus_virtualhost='/'): """ :param audio_folder: audio folder with sub folders, each numbers after a meditation state (e.g, 0, 1, 2, 3, ..). Each folder represents a meditation stage and should contain any tracks for that stage :param up_transition_sound_filename :param down_transition_sound_filename :param sample_rate: the sample rate for the sounds, defaults to 16 Khz """ self.SAMPLE_RATE = sample_rate self.audio_folder = audio_folder self.up_transition_sound_filename = up_transition_sound_filename self.down_transition_sound_filename = down_transition_sound_filename self.playing_tracks = [] self.playing_heartbeats = [] self.playing_transitions = [] self.tracks_by_stage = defaultdict(list) self.performing_a_mix = False self.mixing_thread = None self.bus = RabbitController(bus_host, bus_port, bus_username, bus_password, bus_virtualhost) self.current_stage = None swmixer.init(samplerate=self.SAMPLE_RATE, chunksize=1024, stereo=True) swmixer.start() self.current_playing_track_filename = None self.tracks_last_playing_position = dict() self._validate_audio_files_and_prep_data() sound_controller_channel = self.bus.open_channel() self.bus.subscribe_meditation( self.process_meditation_state_command, existing_channel=sound_controller_channel) self.bus.subscribe_heart_rate( self.process_heart_rate_command, existing_channel=sound_controller_channel) logging.info("waiting for meditation state and heart rates messages..") sound_controller_channel.start_consuming()
def main(args): """ subvertle: the master operations block """ init_settings(args) queue = Queue() # try: if True: # source is our media source. # should contain captions and an RTSP video URL. # - source.captions: list of caption events # - source.rtspUrl: string URL of RTSP stream print " - fetching feed information" source = iplayerlib.fetch(settings.url) translator = translate(settings.dialect,settings.dialectOptions) # mood = moodmeter() # stream = streamer() print " - processing captions (%d)" % len(source.captions) for caption in source.captions: # skip translation for now caption.translated = translator.process(caption.text) # caption.translated = caption.text # print caption.text # print " -> %s" % caption.translated # caption.mood = mood.process(caption.text) print " - initialising audio" swmixer.init(samplerate = 44100, chunksize = 1024) swmixer.start() print " - starting speech generator thread" settings.cachedir = settings.cachedir % source.id # should really handle fail here if not os.path.exists(settings.cachedir): os.mkdir(settings.cachedir) # generator = thread(target = generate_thread, args = (settings, source.captions, queue)) # generator.start() # print " - buffering (%ds)" % settings.buffertime # time.sleep(settings.buffertime) sayqueue = Queue() sayer = thread(target = sayer_thread, args = (sayqueue,)) sayer.start()
def __init__(self, audio_folder, sample_rate=16000): """ :param audio_folder: audio folder with sub folders, each named by start rate and end rate (e.g, 20_40, 41_60). Each folder represents a meditation stage and should contain any tracks for that stage and a heartbeat.wav file :param sample_rate: the sample rate for the sounds """ self.audio_folder = audio_folder self.sample_rate = sample_rate self.current_playing_track_filename = None self.playing_tracks = [] self.playing_heartbeats = [] self.tracks_by_stage = defaultdict(list) self._validate_audio_files_and_prep_data() swmixer.init(samplerate=sample_rate, chunksize=1024, stereo=True) swmixer.start()
from pygame.locals import * from sys import exit import swmixer size = width, height = 320, 240 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) pygame.init() swmixer.init(samplerate=44100, chunksize=1024, stereo=True) swmixer.start() snd1 = swmixer.StreamingSound("../assets/audio/3030.mp3") snd2 = swmixer.StreamingSound("../assets/audio/l1.mp3") snd3 = swmixer.StreamingSound("../assets/audio/l2.mp3") snd4 = swmixer.StreamingSound("../assets/audio/l3.mp3") snd5 = swmixer.StreamingSound("../assets/audio/l4.mp3") snd6 = swmixer.StreamingSound("../assets/audio/l5.mp3") chan1 = snd1.play() chan2 = snd2.play(volume=0.1) chan3 = snd3.play(volume=0.0) chan4 = snd4.play(volume=0.0) chan5 = snd5.play(volume=0.0) chan6 = snd6.play(volume=0.0) while True:
import swmixer import time swmixer.init(samplerate=44100, chunksize=1024, stereo=True) swmixer.start() snd1 = swmixer.Sound("main.wav") snd2 = swmixer.Sound("test2.wav") snd3 = swmixer.Sound("test.wav") snd3.play(loops=-1, volume=0.3) while True: totalValue = 0 for i in range(0, 15): #data = arduino.readline()[:-2] value = arduino.readline()[:-2] if value: print value totalValue += int(value) print totalValue if totalValue > 2: snd2.play(volume=0.4) time.sleep(4.0) snd1.play(volume=0.3) time.sleep(8.0) elif totalValue > 0: snd1.play(volume=0.7) time.sleep(5) time.sleep(1) print "LOL" snd2.play(volume=0.7)
def __init__(self, samplerate=44100, chunksize=1024, stereo=True): self.samplerate = samplerate self.chunksize = chunksize self.stereo = stereo swmixer.init(samplerate=self.samplerate, chunksize=self.chunksize, stereo=self.stereo) swmixer.start()