def generate_sample(self, out_buffer, preview, filename, was_previewed=None): if not was_previewed: print("* Generating audio...") self.output = array(out_buffer, dtype=int16) if preview: print("* Previewing audio...") bytestream = self.output.tobytes() pya = pyaudio.PyAudio() stream = pya.open(format=pya.get_format_from_width(width=2), channels=1, rate=SAMPLE_RATE, output=True) stream.write(bytestream) stream.stop_stream() stream.close() pya.terminate() print("* Audio preview completed!") else: writewav(filename, SAMPLE_RATE, self.output) print("* Wrote audio to %s!" % filename)
def record_sound(hal: PizzaHAL, filename: Any, duration: int, cache: bool = False, **kwargs): """ Record sound using the microphone :param hal: The hardware abstraction object :param filename: The path of the file to record to :param duration: The time to record in seconds :param cache: `True` to save recording to cache. Default is `False` """ myrecording = sd.rec(int(duration * AUDIO_REC_SR), samplerate=AUDIO_REC_SR, channels=2) sd.wait() # Wait until recording is finished writewav(str(filename), AUDIO_REC_SR, myrecording) if cache: hal.soundcache[str(filename)] = (myrecording, AUDIO_REC_SR)
xinicial = 0.28768613 qaux = 0.0 terma = 500 muestras = 300 kmin = 2.9 kmax = 4 datos = open('Bifurcaciones03.dat', 'w') SuperEstable = open('SuperEstable03.dat', 'w') tolerancia = 0.0005 soundata = [] for j in range(1, pruebas): konst = kmin + (kmax - kmin) * j / pruebas Punto = ParticulaLogistica(xinicial, konst) for k in range(0, terma): #primero termalizamos el asunto Punto.step() for k in range(0, muestras): Punto.step() print(konst, Punto.q, k, file=datos) soundata.append(Punto.q) if (abs(Punto.q - 0.5) < tolerancia): print(konst, Punto.q, k, file=SuperEstable) scaled = np.int16(soundata / np.max(np.abs(soundata)) * 32767 * 2) - 32767 writewav('NoiceAtWindows.wav', 44100, scaled)
omega=[] #Una frecuencia diferente para cada Punto.q limite dado konst for k in range(0,terma): #primero termalizamos el asunto Punto.step() for k in range(0,muestras): Punto.step() print(konst, Punto.q, k, file=datos) omega.append(15*np.exp(basefreq*Punto.q)) fases.append(np.modf(10*Punto.q)[0]) for t in range(0, Samples): amplitud=0 for k in range(0,muestras): #amplitud+=OndaPlana(t/SampleRate*2*pi,omega[k],fases[k]) amplitud+=OndaPlana(t/SampleRate*2*pi,omega[k]) soundata.append(amplitud/muestras) print("vamos en la konstante", konst, "numero", j, "de" , pruebas) scaled = np.int16(soundata/np.max(np.abs(soundata)) * 32767) writewav('CharagusquesPruebaLowerPitch.wav', 44100, scaled) end_time=time.time() tiempo=end_time - start_time print (tiempo, " segundos nos tardamos ---" )
xinicial=0.28768613 qaux=0.0 terma=500 muestras=300 kmin=2.9 kmax=4 datos=open('Bifurcaciones03.dat', 'w') SuperEstable=open('SuperEstable03.dat', 'w') tolerancia=0.0005 soundata=[] for j in range(1,pruebas): konst=kmin+(kmax-kmin)*j/pruebas Punto=ParticulaLogistica(xinicial, konst) for k in range(0,terma): #primero termalizamos el asunto Punto.step() for k in range(0,muestras): Punto.step() print(konst, Punto.q, k, file=datos) soundata.append(Punto.q) if(abs(Punto.q-0.5)<tolerancia): print(konst, Punto.q, k, file=SuperEstable) scaled = np.int16(soundata/np.max(np.abs(soundata)) * 32767*2)-32767 writewav('NoiceAtWindows.wav', 44100, scaled)
omega = [] #Una frecuencia diferente para cada Punto.q limite dado konst for k in range(0, terma): #primero termalizamos el asunto Punto.step() for k in range(0, muestras): Punto.step() print(konst, Punto.q, k, file=datos) omega.append(15 * np.exp(basefreq * Punto.q)) fases.append(np.modf(10 * Punto.q)[0]) for t in range(0, Samples): amplitud = 0 for k in range(0, muestras): #amplitud+=OndaPlana(t/SampleRate*2*pi,omega[k],fases[k]) amplitud += OndaPlana(t / SampleRate * 2 * pi, omega[k]) soundata.append(amplitud / muestras) print("vamos en la konstante", konst, "numero", j, "de", pruebas) scaled = np.int16(soundata / np.max(np.abs(soundata)) * 32767) writewav('CharagusquesPruebaLowerPitch.wav', 44100, scaled) end_time = time.time() tiempo = end_time - start_time print(tiempo, " segundos nos tardamos ---")