Skip to content

Instantly share code, notes, and snippets.

@bruno-cadorette
Last active December 29, 2015 20:19
Show Gist options
  • Save bruno-cadorette/7722916 to your computer and use it in GitHub Desktop.
Save bruno-cadorette/7722916 to your computer and use it in GitHub Desktop.
Microsoft Anna sing: the 12 days of christmas!
open System.Speech.Synthesis
open System
type language = {
presents: string array
line: string
lastPrefix: string
suffix: int->string
}
let song language (synth:SpeechSynthesizer) =
let singLine text =
printfn "%s" text
synth.Speak text
let rec daysOfChristmas day =
let rec allPresents n =
if(n>0) then
singLine <| (match n with |1 when day<>1->language.lastPrefix |_-> n.ToString()) + " " + language.presents.[n-1]
allPresents (n-1)
if (day<=language.presents.Length) then
singLine <| String.Format(language.line, day.ToString() + language.suffix day)
allPresents day
daysOfChristmas (day+1)
daysOfChristmas 1
[<EntryPoint>]
let main argv =
let english = {
presents= [|"Partridge in a pear-tree"; "Turtle-doves"; "French hens"; "Colly birds"; "GOLD RING"; "Geese-a-Laying";
"Swans-a-Swimming"; "Maids-a-Milking"; "Ladies Dancing"; "Lords-a-Leaping"; "Pipers Piping"; "Drummers Drumming"|];
line = "On the {0} day of christmas, my true love sent to me. ";
lastPrefix = "And a"
suffix = function |1->"st"|2->"nd"|3->"rd"|_->"th"
}
let french = {
presents = [|"Perdrix dans un Poirier"; "Tourterelles"; "Poules Gloussants"; "Oiseaux Chantants"; "Anneaux d'OR"; "Oies Pondant";
"Cygnes nageant"; "Fermières trayant"; "Dames dansant"; "Messieurs sautant"; "Joueurs de Flûte"; "Joueurs de Tambour"|];
line = "Le {0} jour de noël, mon Grand Amour m'a donné";
lastPrefix = "Et une"
suffix = function |1->"er"|_->"e"
}
use synth = new SpeechSynthesizer()
synth.SelectVoice(synth.GetInstalledVoices() |> Seq.nth(3) |> fun x->x.VoiceInfo.Name)
song english synth
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment