def callback_voice(ch, method, properties, body): wav_file = open('ToSpeak.wav', 'wb') wav_file.write(body) wav_file.close spkr = Sound() spkr.set_volume(100, channel=None) spkr.play_file('ToSpeak.wav') os.remove('ToSpeak.wav') logging.info('Voice message processed')
from test_display import test #执行用例 test() exit() disp = Display() leds = Leds() sounds = Sound() #ts = TouchSensor(INPUT_2) sounds.beep() sleep(1) sounds.set_volume(100) sounds.speak(text='1.15') #sounds.speak(text='Welcome to the E V 3 dev project!') sleep(1) exit() ''' console.reset_console() console.text_at('Hello World!', column=1, row=5, reset_console=True, inverse=True) sleep(2) ''' # 在屏幕上显示字体 if True: #显示有效的Display字体 print(fonts.available(), file=sys.stderr)
g = GyroSensor(INPUT_1) g_off = 0 u = UltrasonicSensor(INPUT_3) c_exists = True try: c = ColorSensor(INPUT_2) c.mode = 'COL-COLOR' except ev3dev2.DeviceNotFound: c_exists = False l = Leds() l.set_color('LEFT', 'AMBER') s = Sound() s.set_volume(100) g_off = 0 f = open("data.txt", "w") CM_PER_ROT = 8.415 # 21.375 for cm right_start = True def color_map(): if c_exists: if c.value() > 1: return "White" else: return "Black" else:
def test(): sounds = Sound() sounds.set_volume(100) sounds.beep() sounds.play_tone(300, 0.2) sleep(1) sounds.play_tone(500, 0.2) sleep(1) sounds.speak('start runing:') sleep(1) sounds.play_song(( ('D4', 'e3'), # intro anacrouse ('D4', 'e3'), ('D4', 'e3'), ('G4', 'h'), # meas 1 ('D5', 'h'), ('C5', 'e3'), # meas 2 ('B4', 'e3'), ('A4', 'e3'), ('G5', 'h'), ('D5', 'q'), ('C5', 'e3'), # meas 3 ('B4', 'e3'), ('A4', 'e3'), ('G5', 'h'), ('D5', 'q'), ('C5', 'e3'), # meas 4 ('B4', 'e3'), ('C5', 'e3'), ('A4', 'h.'), )) sleep(1) sounds.tone([(392, 350, 100), (392, 350, 100), (392, 350, 100), (311.1, 250, 100), (466.2, 25, 100), (392, 350, 100), (311.1, 250, 100), (466.2, 25, 100), (392, 700, 100), (587.32, 350, 100), (587.32, 350, 100), (587.32, 350, 100), (622.26, 250, 100), (466.2, 25, 100), (369.99, 350, 100), (311.1, 250, 100), (466.2, 25, 100), (392, 700, 100), (784, 350, 100), (392, 250, 100), (392, 25, 100), (784, 350, 100), (739.98, 250, 100), (698.46, 25, 100), (659.26, 25, 100), (622.26, 25, 100), (659.26, 50, 400), (415.3, 25, 200), (554.36, 350, 100), (523.25, 250, 100), (493.88, 25, 100), (466.16, 25, 100), (440, 25, 100), (466.16, 50, 400), (311.13, 25, 200), (369.99, 350, 100), (311.13, 250, 100), (392, 25, 100), (466.16, 350, 100), (392, 250, 100), (466.16, 25, 100), (587.32, 700, 100), (784, 350, 100), (392, 250, 100), (392, 25, 100), (784, 350, 100), (739.98, 250, 100), (698.46, 25, 100), (659.26, 25, 100), (622.26, 25, 100), (659.26, 50, 400), (415.3, 25, 200), (554.36, 350, 100), (523.25, 250, 100), (493.88, 25, 100), (466.16, 25, 100), (440, 25, 100), (466.16, 50, 400), (311.13, 25, 200), (392, 350, 100), (311.13, 250, 100), (466.16, 25, 100), (392.00, 300, 150), (311.13, 250, 100), (466.16, 25, 100), (392, 700)]) sounds.play_file('resources/xiaohuamao.wav') sleep(2)
class Guitar: def __init__(self): print("Welcome to EV3 Guitar") self.sound = Sound() # mount function self.multiply = 1 self.pause = False self.volume = 10 # set initial volume self.setVolume(50) def getVolume(self): return int(self.sound.get_volume('Beep')) def setVolume(self, volume): self.sound.set_volume(int(volume), 'Beep') def volumeUp(self, state): if state: if self.volume < 100: self.sound.set_volume(self.volume + 1) def volumeDown(self, state): if state: if self.volume > 0: self.sound.set_volume(self.volume - 1) def backButton(self, state): print("Bye!!") sys.exit() def multiplyUp(self, state): self.multiply = self.multiply + 1 def multiplyDown(self, state): if self.multiply > 1: self.multiply = self.multiply - 1 def togglePause(self, state): if state and self.pause: self.pause = False else: self.pause = True # app run def play(self): delay = 0 step = [5, 10, 15, 20, 25, 30, 35, 40, 45, 55, 60, 65, 70] button = Button() button.on_up = self.volumeUp button.on_down = self.volumeDown button.on_left = self.multiplyUp button.on_right = self.multiplyDown button.on_enter = self.togglePause button.on_backspace = self.backButton ir = InfraredSensor() ts = TouchSensor() servo = MediumMotor() while True: self.volume = self.getVolume() button.process() if self.pause == True: continue distance = int(math.fabs(ir.value())) position = int(math.fabs(servo.position)) for x in step: if distance <= x: hertz = int(x * 15) # print("Hertz - " + str(hertz)) break for x in step: if position <= x: duration = int(x * 5 * self.multiply) # print("Duration - " + str(duration)) break if ts.is_pressed: if delay == 200: delay = 0 else: if delay == 0: delay = 200 # play sound self.sound.tone([(hertz, duration, delay)])