def play_song(s, duration): """""" note = 0 tune = RTTTL(songs.find(s)) for freq, msec in tune.notes(): if note < duration: play_tone(freq, msec) note += 1
def getData(name): tune = RTTTL(songs.find(name)) n = [] d = [] for freq, msec in tune.notes(): n.append(freq) d.append(msec) data = {} data['freqs'] = n data['durs'] = d with open("/Users/rbn/src/upy-rtttl/sptune.json", "w+") as outfile: json.dump(data, outfile)
def getData(name): tune = RTTTL(songs.find(name)) n=[] d=[] for freq, msec in tune.notes(): n.append(freq) d.append(msec) data = {} data['freqs']=n data['durs']=d with open("/Users/rbn/src/upy-rtttl/sptune.json","w+") as outfile: json.dump(data, outfile)
def getSongNumber(message): print(message) msg = cayenne.client.CayenneMessage(message[0], message[1]) if msg.channel == musicChannel: # extract the song number songNo = int(msg.value) print("song number: %d" % songNo) songName = songList.get(songNo) print('Playing the song: %s' % songName) # play the tune tune = RTTTL(songs.find(songName)) for freq, msec in tune.notes(): play_tone(freq, msec)
def getData(unused_addr, args, name): #broadcasts data for ringtone name global playing playing = True tune = RTTTL(songs.find(name)) print("Playing ringtone {}".format(name)) for freq, msec in tune.notes(): #send the data pairs for the notes msg = [] #prepare data message msg.append(freq) msg.append(msec) client.send_message("/ringdata", msg) #broadcast next data pair sleep(msec / 1000.0) #sleep for duration of note #stop current song if playing set to False by received "/abort" message if playing == False: break client.send_message("/finished", True) #broadcasts osc msg when finished
def getData(unused_addr,args,name): #broadcasts data for ringtone name global playing playing=True tune = RTTTL(songs.find(name)) print("Playing ringtone {}".format(name)) for freq, msec in tune.notes(): #send the data pairs for the notes msg=[] #prepare data message msg.append(freq) msg.append(msec) client.send_message("/ringdata",msg) #broadcast next data pair sleep(msec/1000.0) #sleep for duration of note #stop current song if playing set to False by received "/abort" message if playing==False: break client.send_message("/finished",True) #broadcasts osc msg when finished
def play_song(self, search): """ play a song stored in songs.py :param search: string; song name listed in songs.py :return: None """ while self.is_playing: self.mute = True else: self.mute = False # play song in a new thread (non-blocking) # _thread.stack_size(16 * 1024) # set stack size to avoid runtime error # play_tone = _thread.start_new_thread(self.play, (RTTTL(songs.find(search)),)) self.play(RTTTL(songs.find(search))) self.song = None
def getSongNumber(topic, msg): print("Update") print(topic, msg) channelIndex = topic.index( b'cmd') + 4 # search for 'cmd' the channel no follows print("channelIndex: %d" % channelIndex) channel = int(topic[channelIndex:]) # from the channel index to the end print("channel: %d" % channel) valueIndex = msg.index(b'=') + 1 print("valueIndex: %d" % valueIndex) # extract the song number songNo = int(msg[valueIndex:]) print("song number: %d" % songNo) songName = songList.get(songNo) print('Playing the song: %s' % songName) # play the tune tune = RTTTL(songs.find(songName)) for freq, msec in tune.notes(): play_tone(freq, msec)
def test_05_play_rtttl(self): buzz = BuzzerPlayer() if hasattr(buzz, 'play_rtttl'): buzz.play_rtttl(songs.find('Entertainer'))
speaker.duty(512) # 50% duty cycle sleep_ms(int(msec)) # Play for a number of msec speaker.duty(0) # Stop playing sleep_ms(50) # Delay 50 ms between notes song_numbers = os.urandom(100) cnt = 0 print("Push the button to sound the door bell") while True: if btn.value() == PUSHED: song_nr = int(int(song_numbers[cnt])/10.21) +1 songName = songList.get(song_nr) print("Play song ",songName) sleep_ms(20) # debounce switch # play the song tune = RTTTL(songs.find(songName)) for freq, msec in tune.notes(): play_tone(freq, msec) cnt += 1 if cnt > 99: songs = os.urandom(100) cnt = 0 while True: if btn.value() != RELEASED: sleep_ms(20) # debounce switch else: sleep_ms(20) break;
async def play_completely(song): tune = RTTTL(songs.find(song)) for freq, msec in tune.notes(): await play_tone(freq, msec)
# # This particular test was coded for the GHI Electronics G30 Development # Board: https://www.ghielectronics.com/catalog/product/555 # import pyb from rtttl import RTTTL import songs buz_tim = pyb.Timer(3, freq=440) buz_ch = buz_tim.channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.BUZZER, pulse_width=0) def play_tone(freq, msec): print('freq = {:6.1f} msec = {:6.1f}'.format(freq, msec)) if freq > 0: buz_tim.freq(freq) buz_ch.pulse_width_percent(50) pyb.delay(int(msec * 0.9)) buz_ch.pulse_width_percent(0) pyb.delay(int(msec * 0.1)) tune = RTTTL(songs.find('Entertainer')) for freq, msec in tune.notes(): play_tone(freq, msec)
from rtttl import RTTTL import songs import board import pulseio import time speaker_pin = board.D0 # Speaker is connected to this DIGITAL pin # Initialize input/output pins pwm = pulseio.PWMOut(speaker_pin, variable_frequency=True, duty_cycle=0) def play_tone(freq, msec): # print('freq = {:6.1f} msec = {:6.1f}'.format(freq, msec)) if freq > 0: pwm.frequency = int(freq) # Set frequency pwm.duty_cycle = 32767 # 50% duty cycle time.sleep(msec*0.001) # Play for a number of msec pwm.duty_cycle = 0 # Stop playing time.sleep(0.05) # Delay 50 ms between notes tune = RTTTL(songs.find('Entertainer')) for freq, msec in tune.notes(): play_tone(freq, msec)
async def play_song(song): tune = RTTTL(songs.find(song)) for freq, msec in tune.notes(): await play_tone(freq, msec) if not door_state.is_open: return
def play_song(search): play(RTTTL(songs.find(search)))
def play_melody(song='closed'): print("Play melody: ", song) tune = RTTTL(songs.find(song)) for freq, msec in tune.notes(): play_tone(freq, msec) tone.deinit()
await uasyncio.sleep_ms(int(msec * 0.1)) async def play(tune, buz_ch): try: for freq, msec in tune.notes(): await play_tone(freq, msec, buz_ch) except KeyboardInterrupt: await play_tone(0, 0, buz_ch) async def killer(): print("sleeping {} seconds".format(20)) await uasyncio.sleep(20) loop = uasyncio.get_event_loop() loop.create_task(file_to_led()) loop.create_task(temp()) from rtttl import RTTTL import songs loop.create_task(play(RTTTL(songs.find('MissionImp')), buz_ch1)) try: loop.run_until_complete(killer()) finally: buz_ch1.deinit() display.fill(0) display.show()
from rtttl import RTTTL import songs import board import pulseio import time speaker_pin = board.D0 # Speaker is connected to this DIGITAL pin # Initialize input/output pins pwm = pulseio.PWMOut(speaker_pin, variable_frequency=True, duty_cycle=0) def play_tone(freq, msec): # print('freq = {:6.1f} msec = {:6.1f}'.format(freq, msec)) if freq > 0: pwm.frequency = int(freq) # Set frequency pwm.duty_cycle = 32767 # 50% duty cycle time.sleep(msec * 0.001) # Play for a number of msec pwm.duty_cycle = 0 # Stop playing time.sleep(0.05) # Delay 50 ms between notes tune = RTTTL(songs.find('Super Mario - Main Theme')) for freq, msec in tune.notes(): play_tone(freq, msec)