Skip to content

Instantly share code, notes, and snippets.

@sergey-tihon
Created November 13, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-tihon/51e21e328454567594f4 to your computer and use it in GitHub Desktop.
Save sergey-tihon/51e21e328454567594f4 to your computer and use it in GitHub Desktop.
Joke radio powered by COM Type Provider
#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("&quot;","\"")
| _ -> "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