def play_note(*args, **kwargs): """ Selects a random frequency out of NOTE_RANGE and plays it for NOTE_LENGTH seconds. Uses the module pysine. """ pysine.sine(frequency=random.choice(NOTE_RANGE), duration=NOTE_LENGTH)
def randomBeat(): while True: try: tempo = int(input('What would you like the tempo to be? ')) break except ValueError: print('Please input a number') while True: try: percentageChance = int( input( 'What should be the percentage chance of skipping a beat. Please use only a number? ' )) break except ValueError: print('Please input a number') #percentageChance = percentageChance/100 while True: willBeatPlay = randint(1, int(100 / percentageChance)) print(willBeatPlay) print(int(100 / percentageChance)) if willBeatPlay == 1: time.sleep(60 / tempo) else: pysine.sine(frequency=440.0, duration=0.1) time.sleep((60 / tempo) - 0.1)
def play_srs_serial(srs_serial, tone_time=0.2): srs_frq = { 1: 261, #do, C 2: 293, #re 3: 329, #mi 4: 349, #fa 5: 391, #sol 6: 440, #la 7: 466 #si } if windows: for tone_num in srs_serial: frq = srs_frq.get(tone_num, None) if frq != None: winsound.Beep(frq, int(tone_time * 1000)) else: time.sleep(tone_time) else: for tone_num in srs_serial: frq = srs_frq.get(tone_num, None) if frq != None: sine(frequency=frq, duration=tone_time) else: time.sleep(tone_time)
def player(mixer, repeat=2): """Plays sounds with different frequencies and volume levels""" global signal global detected volumes = [1, 2, 4, 6, 8, 10, 14, 18, 22, 26, 30] frequencies = [125, 250, 500, 1000, 2000, 4000, 8000] # shuffle frequencies frequencies = np.repeat(frequencies, repeat) np.random.shuffle(frequencies) mixer.setvolume(0) sleep(0.1) for freq in frequencies: detected = False for vol in volumes: print(freq, vol) for n in range(3): mixer.setvolume(vol) sleep(0.1) signal = [freq, vol, datetime.now()] sine(frequency=freq, duration=0.5) if detected: break if detected: break sleep(2)
def Agogic(): while True: try: timeSig = int(input('How many beats are in a measure? ')) break except ValueError: print('Please input a number') while True: try: tempo = int(input('What would you like the tempo to be? ')) break except ValueError: print('Please input a number') percentageDelay = 2 loop = timeSig - 1 while True: pysine.sine(frequency=440.0, duration=0.15) time.sleep((60 / tempo) - 0.15) while loop > 0: pysine.sine(frequency=440.0, duration=0.1) time.sleep((60 / tempo) - 0.1) loop -= 1 loop = timeSig - 1
def assert_excess_duration(self, duration): t0 = time() sine(duration*1000.0, duration) t1 = time() diff = t1 - t0 -duration assert diff >= -0.1, diff assert diff <= 0.1, diff
def play_taam(seq): for taam in seq: # print(taam) if taam != np.nan: freq = miditofreq(taam) sine(frequency=freq, duration=.3) else: time.sleep(.3)
def play_sound(byteString): # pass in the binary representation as a string (no spaces) for bit in byteString: if int(bit) == 1: sine(frequency=440, duration=0.25) print("bit: ", bit) if int(bit) == 0: sine(frequency=1000, duration=0.25) print("bit: ", bit)
def scale(l, d): for i in range(l+1): f = b*2**(1.0/l*i) print(f) for i in range(l+1): f = b*2**(1.0/l*i) if i in ll: sine(f, d) a = 3
def play(self): for char in self.code: if char == '.': sine(frequency=700, duration=0.15) elif char == '-': sine(frequency=700, duration=0.45) elif char == ' ': pass time.sleep(.1)
def acceldecel(): #Starting tempo input while True: try: startTempo = int(input('Starting tempo: ')) break except ValueError: print('Please input a number') #Ending tempo input while True: try: endTempo = int(input('Ending tempo: ')) break except ValueError: print('Please input a number') #Rate input while True: try: rate = int(input('How often would you like the tempo to change? ')) break except ValueError: print('Please input a number') #Figuring out how many times to loop the code loopAmount = (endTempo - startTempo) * rate loopAmount = abs(loopAmount) #Looping the metronome while loopAmount >= 0: #Generating the tone pysine.sine(frequency=440.0, duration=0.1) #For testing print(str(datetime.datetime.now()) + " " + str((60 / startTempo))) #The delay inbetween beeps time.sleep((60 / startTempo) - 0.1) #Checking to see if the startTempo should go up or down if endTempo > startTempo: startTempo = startTempo + (rate) if startTempo > endTempo: startTempo = startTempo - (rate) #Reducing the loop loopAmount -= 1 #Keeps playing the slowed/sped up tempo while True: pysine.sine(frequency=440.0, duration=0.1) time.sleep((60 / startTempo) - 0.1)
def _delay(self, delay_time, play_tone = False): next_time = self.last_time + delay_time sleep_time = next_time - time.time() #print(f'last_time={self.last_time} delay_time={delay_time} time.clock={time.clock()} next_time={next_time} sleep_time={sleep_time}') self.last_time = next_time if(sleep_time > 0): if(play_tone): sine(duration = sleep_time + 0.03) else: time.sleep(sleep_time)
def steady(): while True: try: tempo = int( input('What tempo would you like the metronome to play at? ')) break except ValueError: print('Please input an integer') while True: pysine.sine(frequency=440.0, duration=0.1) time.sleep((60 / tempo) - 0.1)
def tick(self): frecuencia = self.frecuencia if self.pulso == self.compas: frecuencia = 880 # acento (La agudo) self.pulso = 1 elif self.compas != 0: self.pulso += 1 # Evita que se vaya de madre if self.pulso > self.compas: self.pulso = 1 sine(frequency=frecuencia, duration=self.duracion) # print("Pulso:", self.pulso) time.sleep((60.0 / self.bpm) - self.duracion) # pausa
def greeing(mixer, opening=True): """Plays simple greeting to check sound""" frequencies = [261, 329, 391] durations = [0.2, 0.2, 0.5] mixer.setvolume(30) sleep(0.1) if opening: _ = [ sine(frequency=f, duration=d) for f, d in zip(frequencies, durations) ] else: _ = [ sine(frequency=f, duration=d) for f, d in zip(frequencies[::-1], durations) ] mixer.setvolume(0) sleep(0.1)
def ReproduceLista(lista): """reproduceLista reproduce una lista que contiene un pedazo de la cancion con ayuda de la biblioteca pysine Params ----- lista:[] pedazo de la cancion """ NOTE = 0 ACC = 1 OCTAVE = 2 TIME = 3 n = len(lista) for i in range(n): if lista[i][NOTE] == "Z": #es un silencio sleep(lista[i][TIME]) else: freq = Frecuencia(lista[i][OCTAVE], lista[i][NOTE], lista[i][ACC]) #genera una onda senoidal de determinada frecuencia durante el tiempo indicado sine(freq, lista[i][TIME]) sleep(0.01)
def beatPhasing(): while True: try: tempo = int(input('What would you like the tempo to be? ')) break except ValueError: print('Please input a number') while True: try: phase = int(input('How many beats would you like to disappear? ')) break except ValueError: print('Please input a number') while True: try: beatAmount = int(input('How many beats before the pause? ')) break except ValueError: print('Please input a number') phaseLoop = phase beatLoop = beatAmount while True: while beatLoop > 0: pysine.sine(frequency=440.0, duration=0.1) time.sleep((60 / tempo) - 0.1) beatLoop -= 1 beatLoop = beatAmount while phaseLoop > 0: # print('waiting') time.sleep(60 / tempo) phaseLoop -= 1 phaseLoop = phase
def record(output_filename, sec): FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 16000 CHUNK = 16384 RECORD_SECONDS = sec WAVE_OUTPUT_FILENAME = output_filename audio = pyaudio.PyAudio() sine(frequency=640.0, duration=0.1) sleep(0.2) # start Recording stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) print("recording...") frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) print("finished recording") # stop Recording stream.stop_stream() stream.close() audio.terminate() waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb') waveFile.setnchannels(CHANNELS) waveFile.setsampwidth(audio.get_sample_size(FORMAT)) waveFile.setframerate(RATE) waveFile.writeframes(b''.join(frames)) waveFile.close()
def play_not_found_sound(seconds=0.3): """Play a note indicating an item was not found.""" sine(frequency=220, duration=seconds) # A3
def play_found_sound(seconds=0.1): """Play sequence of notes indicating a found item.""" sine(frequency=523.25, duration=seconds) # C5 sine(frequency=698.46, duration=seconds) # F5 sine(frequency=783.99, duration=seconds) # G5
def notation_play(notation, tempo): for n in range(len(notation)): pysine.sine(notation[n][0], notation[n][1] * tempo * 0.001) pysine.sine(0, 0.01)
def sound(string): ints = to_utf_code(string) char_duration = duration / len(ints) for char in ints: sine(frequency = (char + frequency_offset)*multiplexor, duration = char_duration)
def dah(wpm, freq): duration = ditlen(wpm) * 3 pysine.sine(freq, duration)
from pysine import sine sine(frequency=440.0, duration=3.0)
'B': 493.88, 'Cb': 493.88, 'C': 261.63, 'B#': 261.63, 'C#': 277.18, 'Db': 277.18, 'D': 293.66, 'D#': 311.13, 'Eb': 311.13, 'E': 329.63, 'Fb': 329.63, 'F': 349.23, 'E#': 349.23, 'F#': 369.99, 'Gb': 369.99, 'G': 392.00, 'G#': 415.30, 'Ab': 415.30, 'H': 493.88 } for index, i in enumerate(signature): if (index != len(signature)): cli_ui.dot() else: cli_ui.dot(last=True) sine(frequency=freq[scale[i]], duration=0.5) print() for i in signature: print(scale[i] + ' ', end='') # cli_ui.info_2(' '.join( [for i in signature: scale[i] ])) print()
def sing(f, d): sine(f, d)
def play_sound(i, seconds=0.1): """Play a note representing a bar's magnitude. Calculation based on https://pages.mtu.edu/~suits/NoteFreqCalcs.html.""" sine(frequency=(A3 * TWELFTH_ROOT_2**i), duration=seconds)
def playNotes(notes, tonicIndex): freqs = [synth(n, tonicIndex) for n in notes] for f in freqs: sine(f, .2)
def dit(wpm, freq): duration = ditlen(wpm) pysine.sine(freq, duration)
def randomUpDown(): while True: try: lowEndRange = int( input('What would you like the lowest possible tempo to be? ')) break except ValueError: print('Please input a number') while True: try: highEndRange = int( input( 'What would you like the highest possible tempo to be? ')) break except ValueError: print('Please input a number') tempo = randint(lowEndRange, highEndRange) while True: #1 - tempo go down #2 - tempo go up tempoPlusMinus = randint(1, 2) if tempoPlusMinus == 1: print('-') loop = randint(16, 30) while loop > 0: if tempo < highEndRange: if tempo > lowEndRange: pysine.sine(frequency=440.0, duration=0.1) print((60 / tempo) - 0.1) print(tempo) time.sleep((60 / tempo) - 0.1) tempo -= 0.5 loop -= 1 else: tempo -= 1 break else: tempo += 1 break if tempoPlusMinus == 2: print("+") loop = randint(16, 30) while loop > 0: if tempo > lowEndRange: if tempo < highEndRange: pysine.sine(frequency=440.0, duration=0.1) print((60 / tempo) - 0.1) print(tempo) time.sleep((60 / tempo) - 0.1) tempo += 0.5 loop -= 1 else: tempo -= 1 break else: tempo += 1 break