Example #1
0
def trytospeak():
    sound = Sound()
    #play a standard beep
    sound.beep()

    sleep(2)  # pause for 2 seconds

    # Play a SINGLE 2000 Hz tone for 1.5 seconds
    sound.play_tone(2000, 1.5)

    sleep(2)

    # Play a SEQUENCE of tones
    sound.tone([(200, 2000, 400), (800, 1800, 2000)])

    sleep(2)

    # Play a 500 Hz tone for 1 second and then wait 0.4 seconds
    # before playing the next tone
    # Play the tone three times
    sound.tone([(500, 1000, 400)] * 3)

    sleep(2)

    #text to speech
    sound.speak('Hello, my name is E V 3!')
    sound.speak('watch me talk')
Example #2
0
    def test_tone(self):
        spkr = Sound()
        spkr.connector.play_actual_sound = False
        spkr.tone([
            (392, 350, 100), (492, 350), (292,), ()
        ])

        self.assertEqual(len(self.clientSocketMock.mock_calls), 4)

        fn_name, args, kwargs = self.clientSocketMock.mock_calls[0]
        self.assertEqual(fn_name, 'send_command')
        self.assertDictEqual(args[0].serialize(),
                             {'type': 'SoundCommand', 'duration': 0.350, 'message': 'Playing note with frequency: 392',
                              'soundType': 'note'})

        fn_name, args, kwargs = self.clientSocketMock.mock_calls[1]
        self.assertDictEqual(args[0].serialize(),
                             {'type': 'SoundCommand', 'duration': 0.350, 'message': 'Playing note with frequency: 492',
                              'soundType': 'note'})

        fn_name, args, kwargs = self.clientSocketMock.mock_calls[2]
        self.assertDictEqual(args[0].serialize(),
                             {'type': 'SoundCommand', 'duration': 0.2, 'message': 'Playing note with frequency: 292',
                              'soundType': 'note'})

        fn_name, args, kwargs = self.clientSocketMock.mock_calls[3]
        self.assertDictEqual(args[0].serialize(),
                             {'type': 'SoundCommand', 'duration': 0.2, 'message': 'Playing note with frequency: 440.0',
                              'soundType': 'note'})
Example #3
0
def backup():
    """
    Back away from an obstacle.
    """

    # Sound backup alarm.
    spkr = Sound()
    spkr.tone([(1000, 500, 500)] * 3)

    # Turn backup lights on:
    leds = Leds()

    for light in (Leds.LEFT, Leds.RIGHT):
        leds.set_color(light, Leds.RED)

    # Stop both motors and reverse for 1.5 seconds.
    # `run-timed` command will return immediately, so we will have to wait
    # until both motors are stopped before continuing.
    for m in motors:
        m.stop(stop_action='brake')
        m.run_timed(speed_sp=-500, time_sp=1500)

    # When motor is stopped, its `state` attribute returns empty list.
    # Wait until both motors are stopped:
    while any(m.state for m in motors):
        sleep(0.1)

    # Turn backup lights off:
    for light in (Leds.LEFT, Leds.RIGHT):
        leds.set_color(light, Leds.GREEN)
class El3ctricGuitar:
    NOTES = [1318, 1174, 987, 880, 783, 659, 587, 493, 440, 392, 329, 293]
    N_NOTES = len(NOTES)

    def __init__(
            self, lever_motor_port: str = OUTPUT_D,
            touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4):
        self.lever_motor = MediumMotor(address=lever_motor_port)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        
        self.leds = Leds()

        self.speaker = Sound()

    def start_up(self):
        self.leds.animate_flash(
            color='ORANGE',
            groups=('LEFT', 'RIGHT'),
            sleeptime=0.5,
            duration=3,
            block=True)

        self.lever_motor.on_for_seconds(
            speed=5,
            seconds=1,
            brake=False,
            block=True)

        self.lever_motor.on_for_degrees(
            speed=-5,
            degrees=30,
            brake=True,
            block=True)

        sleep(0.1)

        self.lever_motor.reset()

    def play_music(self):
        if self.touch_sensor.is_released:
            raw = sum(self.ir_sensor.proximity for _ in range(4)) / 4

            self.speaker.tone(
                self.NOTES[min(round(raw / 5), self.N_NOTES - 1)]
                - 11 * self.lever_motor.position,
                100,
                play_type=Sound.PLAY_WAIT_FOR_COMPLETE)

    def main(self):
        self.start_up()
        while True:
            self.play_music()
Example #5
0
def play_sonic(button_pressed: Value, pipe: Pipe):
    child_conn = pipe[1]
    sound = Sound()
    # songs = ['sonic_songs/{}'.format(file) for file in listdir('sonic_songs')]
    # size = len(songs)
    # count = 0
    switch = {
        0: lambda: sound.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)
        ], play_type=Sound.PLAY_NO_WAIT_FOR_COMPLETE),
        1: lambda: (sound.speak("Chomp") for _ in range(5))
    }
    switch.get(0)
    while button_pressed.value == 0:
        switch.get(child_conn.recv())()
Example #6
0
    def test_tone(self):
        flip = 1

        s = Sound()
        tank_drive = MoveTank(OUTPUT_A, OUTPUT_D)

        for x in range(4):
            flip *= -1
            tank_drive.on_for_seconds(SpeedPercent(30 * flip),
                                      SpeedPercent(30 * flip), 1, True, True)
            s.tone([(392, 350, 100), (492, 350), (292, ), ()])
        sleep(3)

        for x in range(4):
            flip *= -1
            tank_drive.on_for_seconds(SpeedPercent(30 * flip),
                                      SpeedPercent(30 * flip), 1, True, True)
            s.tone([(392, 350, 100), (492, 350), (292, ), ()],
                   play_type=Sound.PLAY_NO_WAIT_FOR_COMPLETE)
        sleep(3)
Example #7
0
def imerial():
    my_sound = Sound()
    my_sound.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)])
Example #8
0
from ev3dev2.sound import Sound

mySnd = Sound()
mySnd.beep()
mySnd.speak("Hello, World!")
mySnd.beep()

# mySnd.play_tone(440, 1.5, 0)
mySnd.tone([(440, 500, 0), (880, 1500, 0)])

Example #9
0
class Ui(threading.Thread):
    M_FONT = 'helvB12'

    def __init__(self, config):
        threading.Thread.__init__(self)
        self.roboId = config['id']
        self.threadID = 1
        self.name = 'ui-thread'
        self.isRunning = True
        self.messageText = '-'
        self.statusText = '-'
        self.powerSupplyText = '-'
        self.lcd = Display()
        self.btn = Button()
        self.sound = Sound()
        self.leds = Leds()
        self.theFont = fonts.load(Ui.M_FONT)
        self.lcd.clear()
        self.drawText()
        self.lcd.update()

    def drawText(self):
        self.lcd.draw.text((0, 0), 'RoboRinth', font=self.theFont)
        self.lcd.draw.text((0, 14), 'ID: ' + self.roboId, font=self.theFont)
        self.lcd.draw.text((0, 28),
                           'Status: ' + self.statusText,
                           font=self.theFont)
        self.lcd.draw.text((0, 42),
                           'Msg: ' + self.messageText,
                           font=self.theFont)
        # self.lcd.draw.text((0,56), 'Pwr: ' + self.powerSupplyText, font=self.theFont)

    def run(self):
        while self.isRunning:
            self.lcd.clear()
            self.drawText()
            self.lcd.update()
            self.btn.process()
            sleep(1)
        # sleep(0.5)
        self.lcd.clear()
        self.lcd.draw.rectangle((0, 0, 178, 128), fill='white')
        self.lcd.update()

    def registerBackspaceHandler(self, backspaceHandler):
        self.btn.on_backspace = backspaceHandler

    def stop(self):
        self.isRunning = False
        self.join()

    def setMessageText(self, text):
        self.messageText = text

    def setStatusText(self, text):
        self.statusText = text

    def setPowerSupplyText(self, text):
        self.powerSupplyText = text

    def playStartSound(self):
        self.sound.tone([(800, 200, 0), (1200, 400, 100)])

    def setStatusLed(self, color):
        if color == 'green':
            self.leds.set_color('RIGHT', 'GREEN')
        elif color == 'orange':
            self.leds.set_color('RIGHT', 'ORANGE')
        else:
            print('unsupported color: ' + str(color))
Example #10
0
#!/usr/bin/env python3

from ev3dev2.sound import Sound
from ev3dev2.sensor.lego import ColorSensor
from time import sleep

sound = Sound()
cs = ColorSensor()

sound.beep()
for x in range(10):
    color = cs.color
    if color != cs.COLOR_NOCOLOR:
        sound.speak(cs.COLORS[color])
    else:
        sound.tone([(900, 500, 500)])
    sleep(1)
Example #11
0
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)
Example #12
0
from ev3dev2.sound import Sound

sound = Sound()

# Play a 200Hz tone for 2 seconds and then wait 0.4 seconds
# before playing the next tone, 800Hz for 1 second
# followed by a 3 second delay
sound.tone([(200, 2000, 400), (800, 1000, 3000)])
Example #13
0
# Tank pair
tank_pair = MoveTank(OUTPUT_B, OUTPUT_C)

# Infrared remote
ir = InfraredSensor()
ir.mode = ir.MODE_IR_REMOTE

sound = Sound()
# Play a standard beep on boot up
sound.beep()

while True:
    button_code = ir.value()
    if button_code == ir.TOP_LEFT:
        tank_pair.on(left_speed=100, right_speed=100)
    elif button_code == ir.TOP_LEFT_BOTTOM_LEFT:
        tank_pair.on(left_speed=100, right_speed=0)
    elif button_code == ir.TOP_LEFT_TOP_RIGHT:
        tank_pair.on(left_speed=0, right_speed=100)
    elif button_code == ir.TOP_RIGHT:
        tank_pair.on(left_speed=-100, right_speed=100)
    elif button_code == ir.BOTTOM_RIGHT:
        tank_pair.on(left_speed=-100, right_speed=-100)
    elif button_code == ir.BOTTOM_LEFT:
        tank_pair.on(left_speed=100, right_speed=-100)
    elif button_code == ir.TOP_LEFT_BOTTOM_RIGHT:
        sound.tone([(500, 1000, 400)] * 3)
    else:
        tank_pair.off()
    sleep(0.01)
Example #14
0
            play_type=Sound.PLAY_NO_WAIT_FOR_COMPLETE)
sleep(3)

for x in range(4):
    drive()
    s.play_tone(500, duration=2, volume=50, play_type=1)
sleep(3)

for x in range(4):
    drive()
    s.play_tone(500, duration=2, volume=50, play_type=0)
sleep(3)

for x in range(4):
    drive()
    s.tone([(392, 350, 100), (492, 350), (292, ), ()])
sleep(3)

for x in range(4):
    drive()
    s.tone([(392, 350, 100), (492, 350), (292, ), ()],
           play_type=Sound.PLAY_NO_WAIT_FOR_COMPLETE)
sleep(3)

for x in range(4):
    drive()
    s.play_note("C4", 0.5)
sleep(3)

for x in range(4):
    drive()
Example #15
0
def main():
    sensLight = ColorSensor(INPUT_1)
    #     sensColor = ColorSensor(INPUT_4)
    #     sensColor.mode = sensColor.MODE_COL_COLOR
    btn = Button()
    sound = Sound()
    steerPair = MoveSteering(OUTPUT_B, OUTPUT_C)

    #     lastColor = sensColor.color_name

    speed = 90
    kP = 2
    kI = 0.1
    kD = 0.5

    target = 30
    error = 0
    lastError = 0
    turn = 0

    errorAccu = 0
    integral = 0

    sound.tone([(400, 400, 20), (800, 800, 20)])

    while not btn.any():
        sleep(0.1)

    sound.beep()
    sleep(2)

    debug_print('Error; Proportial; Integral; Derivative; Turn')
    while not btn.any():
        lightValue = sensLight.reflected_light_intensity
        # colorName = sensColor.color_name

        # detect edge
        if lightValue == 0:
            steerPair.off()
            sleep(0.01)
            continue

        error = target - lightValue

        errorAccu += error
        derivative = error - lastError

        # limit integral
        if errorAccu > 200:
            errorAccu = 200
        elif errorAccu < -200:
            errorAccu = -200

        # apply gains
        proportional = error * kP
        integral = errorAccu * kI
        derivative *= kD

        # calculate turn value
        turn = proportional + integral + derivative

        # limit turn value
        if turn > 100:
            turn = 100
        elif turn < -100:
            turn = -100

        steerPair.on(int(turn * 1), speed)
        debug_print('{}; {}; {}; {}; {}'.format(int(error), int(proportional),
                                                int(integral), int(derivative),
                                                int(turn)))
        # if lastColor != colorName:
        #         sound.speak(colorName)

        lastError = error  # set current error to lastError at the end of the loop
        # lastColor = sensColor.color_name

        sleep(0.02)
Example #16
0
    # Flags
    global log_thread_started
    log_thread_started = False
    wall = False
    reverse = False

    # Server settings
    host = '192.168.43.219'
    port = 12397

    # Server initialization
    print('Initializing server...')
    server = socket.TCPServer(
        (host, port), TCPHandler
    )  # Creates the server, binding to the specified host and port

    # Secondary threads initialization
    print('Initializing threads...')
    ultrasonicThread = UltrasonicThread()
    ultrasonicThread.start()
    # infoThread = InfoThread()
    # infoThread.start()

    print('Ready.')
    print()
    readySound = Sound()
    readySound.tone(1000, 3)

    server.serve_forever(
    )  # Activates the server, which will keep running until the user stops the program with Ctrl+C (KeyboardInterrupt exception)
Example #17
0
    sleep(0.5)
    sound.tone(300, 200)


searchThread = Thread(
    target=findTrack
)  # Create a thread that will execute the playtone function
searchThread.setDaemon(
    True)  # Make the thread a deamon ( will stop when main program stops )

#Checking Color, Interupting thread if not==black
cl = ColorSensor()
while not btn.backspace:
    if (cl.reflected_light_intensity > 42.5 and driveThread.is_alive()):
        onTrack = False
        #searchThread = Thread(target=findTrack)  # Create a thread that will execute the playtone function
        #searchThread.setDaemon(True)  # Make the thread a deamon ( will stop when main program stops )
        #searchThread.start()
        findTrack()
        onTrack = True
        driveThread = Thread(
            target=goForwards
        )  # Create a thread that will execute the playtone function
        driveThread.setDaemon(
            True
        )  # Make the thread a deamon ( will stop when main program stops )
        driveThread.start()  # Run the thread
        sound.tone(1000, 200)  # 1000 Hz for 0.2 s

sound.beep()
leds.all_off()
Example #18
0
        sleep(5)
        start_time = int(round(time.time() * 1000))

    light_intensity = cl.reflected_light_intensity
    if light_intensity > 20:
        # White Part of the Board 
        LMC.off()
        RMC.off()

        # This code attempts micro adjustments
        doTurn(25,-25,25,'LEFT')
        doTurn(-25,25,50,'RIGHT')

        # Try a bigger adjustment if the micro didn't work
        doTurn(25,-25,100,'LEFT')
        doTurn(-25,25,200,'RIGHT')

        LMC.off()
        RMC.off()

        # End of course or lost
        light_intensity = cl.reflected_light_intensity
        if light_intensity > 20:
            sound.tone(  [  (1000, 100, 0),  (1000, 100, 0),  (100, 100, 0),  (100, 100, 0)  ]  )

    else:
        # Black Part of the Board 
        leds.all_off()

        RMC.on(100)
        LMC.on(100)
Example #19
0
    print("Rotation set successfully")

#Set time variables
curtime = (time.time())
time.sleep(2.3)
oldtime = (time.time())


#Define what happens when a key is pressed,
#while making sure that at least 2 seconds have passed
def key_press(key):
    global curtime
    global oldtime
    curtime = (time.time())
    if (curtime - 2) >= oldtime:
        lm.on_for_rotations(25, rot)
        time.sleep(0.5)
        oldtime = time.time()


#Start waiting for a key to be pressed. The (key_press) part is what happens,
#see above for the key_press function
keyboard.on_press(key_press)

#Play a tune so that the user knows that the script is ready
sound.tone([(493.88, 500, 500), (440, 500, 500), (523.25, 500, 500)])

#Keep the program alive
while True:
    time.sleep(0.1)
Example #20
0
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)])
Example #21
0
#!/usr/bin/env python3
from ev3dev2.sound import Sound
from time import sleep

sound = Sound()

#play a standard beep
sound.beep()
sleep(2)  # pause for 2 seconds

# Play a SINGLE 2000 Hz tone for 1.5 seconds
sound.play_tone(2000, 1.5)
sleep(2)

# Play a SEQUENCE of tones
sound.tone([(200, 2000, 400), (800, 1800, 2000)])
sleep(2)

# Play a 500 Hz tone for 1 second and then wait 0.4 seconds
# before playing the next tone
# Play the tone three times
# [(500, 1000, 400)] * 3 is the same as
# [(500, 1000, 400), (500, 1000, 400), (500, 1000, 400)]
sound.tone([(500, 1000, 400)] * 3)
sleep(2)

#text to speech
sound.speak('Hello, my name is E V 3!')
Example #22
0
def sound():
    my_sound = Sound()
    my_sound.tone([(392, 350, 100)])