Audio
Un tono
Un programa sencillo de dar un tono puede ser el siguiente
import cyberpi
cyberpi.audio.set_vol(100)
cyberpi.audio.play_tone(700,1)
Extraído de https://github.com/PerfecXX/Python-mBot2/blob/main/README.md licencia MIT
Instrumentos
También podemos reproducir instrumentos
import cyberpi
cyberpi.audio.set_vol(100)
# str type eg. snare,bass-drum,side-stick,crash-cymbal,open-hi-hat,close-hi-hat,tambourine,hand-clap,claves
# float beat > 0 (second)
cyberpi.audio.play_drum("snare",1)
cyberpi.audio.play_drum("snare",1)
cyberpi.audio.play_drum("side-stick",1)
cyberpi.audio.play_drum("tambourine",1)
Extraído de https://github.com/PerfecXX/Python-mBot2/blob/main/README.md licencia MIT
Efectos sonoros
También este código nos selecciona varios efectos sonoros y los reproduce
import cyberpi
sound_effect = ["hello","hi","bye","yeah","wow","laugh","hum","sad","sigh","annoyed","angry","surprised","yummy","curious","embarrassed","ready","sprint","sleepy","meow","start","switch","beeps","buzzing","explosion","jump","laser","level-up","low-energy","prompt-tone","right","wrong","ring","score","wake","warning","metal-clash","shot","glass-clink","inflator","running water","clockwork","click","current","switch","wood-hit","iron","drop","bubble","wave","magic","spitfire","heartbeat","load"]
cyberpi.display.show_label('UP :GO UP\nDOWN:GO DOWN\nMID :PLAY EFFECT', 16, 0, 0, 0)
cyberpi.display.show_label('SELECT:\nName:', 16, 0, 60, 1)
selected = 0
min_effect = 0
max_effect = len(sound_effect) - 1
while True:
if cyberpi.controller.is_press('up'):
if selected < max_effect:
selected += 1
else:
selected = min_effect
elif cyberpi.controller.is_press('down'):
if selected > min_effect:
selected -= 1
else:
selected = max_effect
elif cyberpi.controller.is_press('middle'):
cyberpi.led.on(255,0,0,id="all")
cyberpi.audio.play_until(sound_effect[selected])
cyberpi.led.on(0,0,0,id="all")
cyberpi.display.show_label('{}'.format(selected), 16, 60, 60, 2)
cyberpi.display.show_label('{}'.format(sound_effect[selected]), 12, 52, 80, 3)
Extraído de https://github.com/PerfecXX/Python-mBot2/blob/main/README.md licencia MIT
Grabadora
O hacernos una grabadora de bolsillo
import cyberpi
from time import sleep
cyberpi.audio.set_vol(100)
cyberpi.display.show_label("A:Start Recording\nB:Play Recording",12,0,0,0)
while True:
cyberpi.display.show_label("Waiting.",16,0,40,1)
if cyberpi.controller.is_press('a'):
cyberpi.led.on(0,255,0,id="all")
cyberpi.display.show_label("Listening..",16,0,40,1)
cyberpi.audio.record()
sleep(5)
cyberpi.display.show_label("Finished..",16,0,40,1)
cyberpi.audio.stop_record()
elif cyberpi.controller.is_press('b'):
cyberpi.led.on(0,0,255,id="all")
cyberpi.display.show_label("Playing..",16,0,40,1)
cyberpi.audio.play_record_until()
cyberpi.display.show_label("Finished..",16,0,40,1)
cyberpi.display.show_label("Waiting...",16,0,40,1)
cyberpi.led.on(0,0,0,id="all")
Extraído de https://github.com/PerfecXX/Python-mBot2/blob/main/README.md licencia MIT
No Comments