Missile Launchers with F#
- Posted: Jan 25, 2010 at 6:48 AM
- 1,174 Views
Chris Smith had a talk at the CodeMash conference in January 2010 titled “Being an Evil Genius with F# and .NET”. Chris created a post about his talk and doing Computer Vision, Speech Recognition, and shooting missiles at people all with F#!
Here is a bit of his speech recognition code using the System.Speech.dll:
let recognizerEvent = getWordRecognizer() // Main handler - convert spoken text into RL commands let handleWord spokenText = printfn "Recognized Word: %s" spokenText let action = match spokenText with | "up" // Has a hard time recognizing this :( | "north" -> MoveUp(20) | "down" -> MoveDown(20) | "left" -> MoveLeft(20) | "right" -> MoveRight(20) | "fire" -> Fire | _ -> NoOp performAction rocketLauncher action |> ignore // Exit handler - specifically look for exit/quit let terminateLoop = ref false let terminateLoopHandler = function | "exit" | "quit" -> terminateLoop := true | _ -> () // Hook up event handlers recognizerEvent.Add(handleWord) recognizerEvent.Add(terminateLoopHandler) while terminateLoop.Value = false do System.Threading.Thread.Yield() |> ignore ()
Chris happily provided the source code as well, RocketLauncher_v1.0.zip.