Joke radio powered by COM Type Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "../packages/FSharp.ComProvider.1.0.0-pre1/lib/net40/FSharp.ComProvider.dll" | |
#r @"../packages/FSharp.Data.2.1.0/lib/net40/FSharp.Data.dll" | |
open FSharp.Data | |
type SpeechService = TypeLib.``Microsoft Speech Object Library``.``5.4`` | |
let speech = SpeechService.SpVoiceClass() | |
type js = JsonProvider<"""{ "type": "success", "value": { "id": 42, "joke": "Joke here." } }""" > | |
let getJoke num = | |
let jokeNum = | |
match num with | |
| Some(x) -> x.ToString() | |
| None -> "random" | |
match Http.Request("http://api.icndb.com/jokes/"+jokeNum).Body with | |
| Text(text) -> | |
let resp = js.Parse(text).Value | |
printfn "%d: %s" resp.Id resp.Joke | |
resp.Joke.Replace(""","\"") | |
| _ -> "It is not funny !!!" | |
[Some 449; Some 489; Some 567; Some 481; None; None; None] | |
|> List.map (getJoke >> speech.Speak) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment