File: test_speech.py

package info (click to toggle)
firmware-microbit-micropython 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 25,448 kB
  • sloc: ansic: 83,496; cpp: 27,664; python: 2,475; asm: 274; makefile: 245; javascript: 41; sh: 25
file content (38 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# test speech module

import microbit
import speech

def test_funcs():
    print('Testing basic functions')
    ph = speech.translate('hello world')
    assert ph == ' /HEHLOW WERLD'
    speech.pronounce('PIHTHUN', pitch=32, speed=60, mouth=100, throat=150)
    speech.say('hello')
    speech.sing('YEHSTERDEY5')

def test_sleep():
    # check that sleep works ok with speech because they both use low-level timers
    # (this is really a test of the audio module)
    print('Testing sleep with speech')
    microbit.sleep(1)
    speech.say('hello world')
    microbit.sleep(1)

def test_timing():
    # test that speech takes the correct amount of time over many runs
    print('Testing timing of say function')
    for i in range(5):
        start = microbit.running_time()
        speech.say('hello world')
        microbit.sleep(1)
        stop = microbit.running_time()
        assert 800 < stop - start < 815

try:
    test_funcs()
    test_sleep()
    test_timing()
    print('Speech test: PASS')
except Exception as ae:
    raise