-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.ts
More file actions
125 lines (121 loc) · 3.42 KB
/
Copy pathmain.ts
File metadata and controls
125 lines (121 loc) · 3.42 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Preset voice
*/
enum BillyVoicePreset {
//% block="elf"
Elf = 1,
//% block="little robot"
LittleRobot = 2,
//% block="stuffy guy"
StuffyGuy = 3,
//% block="little old lady"
LittleOldLady = 4,
//% block="extra_terrestrial"
ExtraTerrestrial = 5,
//% block="default"
Sam = 6,
//% block="dalek"
Dalek = 7
}
/**
* Text to speech extension
*/
//% block="Billy"
//% weight=100 color=#7f00ff icon="\uf028"
namespace billy {
/**
* Say the following text
* @param text words to say
*/
//% block
//% group="micro:bit (V2)"
//% weight=10
export function say(text: string): void {
sayShim(text)
}
/**
* Pronounce the following phonemes
* e.g. "I am a computer" is "AY4 AEM AH KUMPYUW3TER"
* @param phonemes phonemes to pronounce
*/
//% block
//% group="micro:bit (V2)"
//% weight=7
export function pronounce(phonemes: string): void {
pronounceShim(phonemes)
}
/**
* Change the voice preset
* @param voicePreset Type of voice to use
*/
//% block Change voice preset
//% group="micro:bit (V2)"
//% weight=9
export function voicePreset(voicePreset: BillyVoicePreset): void {
switch (voicePreset) {
case BillyVoicePreset.Elf:
configureVoice(183, 64, 110, 160)
break
case BillyVoicePreset.LittleRobot:
configureVoice(163, 60, 190, 190)
break
case BillyVoicePreset.StuffyGuy:
configureVoice(173, 72, 110, 105)
break
case BillyVoicePreset.LittleOldLady:
configureVoice(173, 32, 145, 145)
break
case BillyVoicePreset.ExtraTerrestrial:
configureVoice(155, 64, 150, 200)
break
case BillyVoicePreset.Sam:
configureVoice(183, 64, 128, 128)
break
case BillyVoicePreset.Dalek:
configureVoice(135, 100, 100, 200)
break
default:
break
}
}
/**
* Configure voice parameters
* @param speed how quickly the voice talks. 0 slow, 255 fast.
* @param pitch how high or low the voice sounds
* @param throat how relaxed or tense is the tone of voice
* @param mouth how tight-lipped or overtly enunciating the voice sounds
*/
//% block Configure Voice
//% speed.min=1 speed.max=255 speed.defl=72
//% pitch.min=1 pitch.max=255 pitch.defl=64
//% throat.min=1 throat.max=255 throat.defl=128
//% mouth.min=1 mouth.max=255 mouth.defl=128
//% group="micro:bit (V2)"
//% weight=8
export function configureVoice(speed: number, pitch: number, throat: number, mouth: number): void {
/*
* Original SAM uses 0 as fast 255 as slow.
* Flip it and reverse it.
*/
configureVoiceShim(255 - speed, pitch, throat, mouth)
}
/**
*
*/
//% shim=billy::configureVoiceShim
function configureVoiceShim(speed: number, pitch: number, throat: number, mouth: number): void {
console.log("configureVoice")
}
/**
*/
//% shim=billy::sayShim
function sayShim(text: string): void {
console.log(text)
}
/**
*/
//% shim=billy::pronounceShim
function pronounceShim(phonemes: string): void {
console.log(phonemes)
}
}