Coder Social home page Coder Social logo

speak-swiftly's Introduction

SpeakSwiftly Carthage compatible

Tell your computer what to do

What?

SpeakSwiftly is an experimental, grammar-based speech recognition framework for OSX. It sits atop the Carbon API and provides a simple, DSL-like interface for creating grammars. Parts of the grammars may be annotated for extracting meaning from the resulting grammars in a composable way.

SpeakSwiftly is highly experimental, and the interfaces may change with any commit

Usage Example

/*
 * Build a grammar
 */
var airline = SGChoice(pickFromStringsWithValues: [
    "speedbird": "BAW",
    "united": "UAL",
    "cactus": "AWE",
    "aircanada": "ACA",
    "cessna": "N"
    ])

// (some) nato phonetic numbers
var nato = SGChoice(pickFromStrings: ["alpha", "bravo", "charlie"], withValues: {
    $0.substringToIndex($0.startIndex.advancedBy(1)).uppercaseString
})
nato.setValue(joinAsString) // this utility is provided by SpeakSwiftly

// (some) numbers
let number = SGChoice(pickFromStringsWithValues: [
    "zero": "0", "one": "1", "two": "2", "three": "3"])
number.setValue(joinAsString)

//  EG: N241AB, BAW2451
//  The airline may be omitted if unambiguous after initial contact
let numbers = number.repeated(3, atMost: 4).setValue(flatJoinAsString)
let letters = nato.repeated(exactly: 2).setValue(flatJoinAsString)
let name = airline.optionally().then(numbers).then(letters.optionally())
            .withTag("name") // we'll be able to extract the name using this tag
            .setValue(flatJoinAsString) // this is also provided by SpeakSwiftly

// just to prove tag extraction is real, add some words
let grammar = SGWord(from: "hello").then(name)
/*
 * Attach your delegates
 */
var recognizer = SpeechRecognizer()
recognizer.textDelegate = SpeechTextAdapter(with: { 
    /*
     * If you just want the text, it's quite easy to get
     */
    println("Text: `\($0)`") 
})
recognizer.meaningDelegate = SpeechMeaningAdapter(with: { 
    /*
     * The meaning delegate gives you a dictionary
     *  containing the values of matched tags
     */
    var name = $0["name"]
    println("Found name:: \(name)") 
})

// go!
recognizer.setGrammar(grammar)
recognizer.start()

speak-swiftly's People

Contributors

dhleong avatar

Stargazers

Nick Arner avatar Razzi Abuissa avatar David Cairns avatar lisper avatar

Watchers

 avatar James Cloos avatar

Forkers

mainvolume-hq

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.