コード例 #1
0
ファイル: swmixer.py プロジェクト: cutun/kazoo
def mic_test (play_background = False):
  """records and plays back data from the microphone
  while playing a test sound in the background.
    
  (2009:12:10) XXX this has high latency"""

  import sys
  import swmixer
  import numpy

  swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True)

  if play_background:
    snd = swmixer.Sound("test.wav")
    snd.play(loops=-1)

  micdata = []
  frame = 0

  while True:
    swmixer.tick()
    frame += 1
    if frame < 50:
      micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 50:
      micsnd = swmixer.Sound(data=micdata)
      micsnd.play()
      micdata = []
      frame = 0
コード例 #2
0
    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()
コード例 #3
0
ファイル: runner.py プロジェクト: ideoforms/subvertle
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()
コード例 #4
0
    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()
コード例 #5
0
ファイル: Ploo.py プロジェクト: Cre0/cre0Pli_rtj00
import pygame
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)
コード例 #6
0
ファイル: test4.py プロジェクト: ypcs/pygalaxy
import sys
import swmixer
import numpy

swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True, input_device_index=1)
snd = swmixer.Sound("test1.wav")
snd.play(loops=-1)

micdata = []
frame = 0

while True:
    swmixer.tick()
    frame += 1
    if frame < 50:
        micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 50:
        micsnd = swmixer.Sound(data=micdata)
        micsnd.play()
        micdata = []
        frame = 0

    

コード例 #7
0
ファイル: PlaySoundSWMixer.py プロジェクト: YDutchy/Froque
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)
コード例 #8
0
VOLUME_STEP = os.getenv('VOLUME_STEP', 1)
TUNED_LED_PIN = int(os.getenv('TUNED_LED_PIN', 25))
VOLUME_PIN_CLK = int(os.getenv('VOLUME_PIN_CLK', 5))
VOLUME_PIN_DT = int(os.getenv('VOLUME_PIN_DT', 6))
VOLUME_PIN_SW = int(os.getenv('VOLUME_PIN_SW', 13))
TUNING_PIN_CLK = int(os.getenv('TUNING_PIN_CLK', 17))
TUNING_PIN_DT = int(os.getenv('TUNING_PIN_DT', 27))
TUNING_PIN_SW = int(os.getenv('TUNING_PIN_SW', 22))
AUDIO_DEVICE_INDEX = int(os.getenv('AUDIO_DEVICE_INDEX', 1))

MIN_VFREQ = 1
MAX_VFREQ = 300  # TODO: create a user-friendly env var to customize the transition speed from a station to the next?

try:
    swmixer.init(
        stereo=True, samplerate=44100, output_device_index=AUDIO_DEVICE_INDEX
    )  # To list device IDs: https://stackoverflow.com/a/39677871/2544016
    swmixer.start()
    logger.info("Started swmixer")
except BaseException as e:
    logger.error("Couldn't start swmixer: " + str(e.message))

if has_gpio:
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(TUNED_LED_PIN, GPIO.OUT)

# TODO: scan the audio directory intead of hardcoding the filenames

FILES = []
for root, dirs, files in os.walk(os.path.abspath(AUDIO_PATH)):
    for file in sorted(files):
コード例 #9
0
ファイル: sound-in.py プロジェクト: jarydu/autodoc
import sys
import swmixer
import numpy

swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True)
#snd = swmixer.Sound("test1.wav")
#snd.play(loops=-1)

micdata = []
frame = 0

while True:
    swmixer.tick()
    frame += 1
    if frame < 10:
        micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 10:
        micsnd = swmixer.Sound(data=micdata)
        micsnd.play()
        micdata = []
        frame = 0
コード例 #10
0
ファイル: test4.py プロジェクト: ohisama/PyAudioMixer
import sys
import swmixer
import numpy

swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True)
snd = swmixer.Sound("test1.wav")
snd.play(loops=-1)

micdata = []
frame = 0

while True:
    swmixer.tick()
    frame += 1
    if frame < 50:
        micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 50:
        micsnd = swmixer.Sound(data=micdata)
        micsnd.play()
        micdata = []
        frame = 0

    

コード例 #11
0
        sound['status'] = STATUS_STOP


def load_sounds_and_keys():
    with open('sounds.json') as f:
        data = json.loads(f.read())['sounds']

        def parse_sound(x):
            return {
                'loops': x.get('loops', 0),
                'pause': x.get('pause', 0),
                'sound': x['sound']
            }
        return map(parse_sound, data), map(lambda x: x['key'], data)


if __name__ == '__main__':
    STATUS_PLAY = 'play'
    STATUS_STOP = 'stop'

    swmixer.init(chunksize=1024, stereo=True)
    swmixer.start()

    sounds, watched_keys = load_sounds_and_keys()
    sounds_running = {}

    hm = HookManager()
    hm.HookKeyboard()
    hm.KeyUp = handle_event
    hm.start()
    print("\n\nPress \"Escape\" to exit\n\n")
コード例 #12
0
ファイル: test5.py プロジェクト: ohisama/PyAudioMixer
import sys
import swmixer
import numpy

# Test of multiple soundcards
# You need two soundcards plus a USB mic for this one

swmixer.init(samplerate=44100,
             chunksize=1024,
             stereo=False,
             microphone=True,
             output_device_index=1,
             input_device_index=2)
snd = swmixer.Sound("test1.wav")
snd.play(loops=-1)

micdata = []
frame = 0

while True:
    swmixer.tick()
    frame += 1
    if frame < 50:
        micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 50:
        micsnd = swmixer.Sound(data=micdata)
        micsnd.play()
        micdata = []
        frame = 0
コード例 #13
0
ファイル: audio_control.py プロジェクト: davidjonas/Mediawerf
 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()
コード例 #14
0
ファイル: main.py プロジェクト: raphaelyancey/Virtual_FM_Band
VOLUME_STEP = os.getenv('VOLUME_STEP', 1)
TUNED_LED_PIN = int(os.getenv('TUNED_LED_PIN', 25))
VOLUME_PIN_CLK = int(os.getenv('VOLUME_PIN_CLK', 5))
VOLUME_PIN_DT = int(os.getenv('VOLUME_PIN_DT', 6))
VOLUME_PIN_SW = int(os.getenv('VOLUME_PIN_SW', 13))
TUNING_PIN_CLK = int(os.getenv('TUNING_PIN_CLK', 17))
TUNING_PIN_DT = int(os.getenv('TUNING_PIN_DT', 27))
TUNING_PIN_SW = int(os.getenv('TUNING_PIN_SW', 22))
AUDIO_DEVICE_INDEX = int(os.getenv('AUDIO_DEVICE_INDEX', 1))

MIN_VFREQ = 1
MAX_VFREQ = 300  # TODO: create a user-friendly env var to customize the transition speed from a station to the next?

try:
    swmixer.init(stereo=True,
                 samplerate=44100,
                 output_device_index=AUDIO_DEVICE_INDEX
                 )  # To list device IDs, see README
    swmixer.start()
    logger.info("Started swmixer")
except BaseException as e:
    logger.error("Couldn't start swmixer: " + str(e.message))

if has_gpio:
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(TUNED_LED_PIN, GPIO.OUT)

# TODO: scan the audio directory intead of hardcoding the filenames

FILES = []
for root, dirs, files in os.walk(os.path.abspath(AUDIO_PATH)):
    for file in sorted(files):