-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speech.fs
41 lines (31 loc) · 1.06 KB
/
Speech.fs
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
module BlindfoldChessTraining.Speech
open FSharpx.Collections
open Microsoft.Maui.Media
let safeLocaleIndex locales localeIndex =
if localeIndex <= LazyList.length locales then
localeIndex
else
0
let loadLocales () =
async {
let! locales = TextToSpeech.GetLocalesAsync() |> Async.AwaitTask
let validLocales =
locales
|> Seq.filter (fun loc -> loc.Name <> null && loc.Name.Trim() <> "")
|> Seq.sortBy (fun loc -> loc.Name)
|> LazyList.ofSeq
return validLocales
}
let localeNamesPreDefaulted locales =
locales
|> LazyList.map (fun (loc: Locale) -> loc.Name)
|> LazyList.cons "Default"
|> LazyList.toList
let speak pitch locales localeIndex text =
let pitch = System.Nullable pitch
let i = safeLocaleIndex locales localeIndex
let settings =
match i with
| 0 -> SpeechOptions(Pitch = pitch)
| v -> SpeechOptions(Pitch = pitch, Locale = Seq.item (v - 1) locales)
TextToSpeech.SpeakAsync(text, settings) |> Async.AwaitTask