Giter Club home page Giter Club logo

witai's Introduction

wit.ai GoDoc

Go library for wit.ai Natural Language Processing API. This library integrates with libwit locally and can perform both blocking and non-blocking voice queries using wit.ai service.

Dependencies

In order to start using this library you will need an account on https://wit.ai/. Make sure you complete the Quick Start guide to get yourself all set up.

Other dependencies:

  • Latest libwit (can be downloaded from wit.ai Releases).
  • libsox (brew install sox on OSX).
  • libcurl (brew install curl on OSX).

Usage

package main

import (
	"flag"
	"log"

	"github.com/ianschenck/envflag"
	"github.com/neurodrone/witai"
)

func main() {
	var (
		// This points to the client access token for your account on wit.ai, that you
		// will possibly have stored within an environment variable.
		accessToken = envflag.String("ACCESS_TOKEN", "", "WIT client access token")

		// The recording device you will use for voice queries.
		// Usually, you can leave it be default.
		device = flag.String("device", witai.DefaultDevice, "device name for recording input")
	)
	envflag.Parse()
	flag.Parse()

	// Create a new wit-ai context that will be used for queries.
	ctx, err := witai.NewContext(*device, *accessToken, witai.Error)
	if err != nil {
		log.Fatalln("cannot create new wit-ai context:", err)
	}

	// Always make sure to close the context once you are done.
	defer ctx.Close()

	log.Println("Say something nice now: ...")

	done := make(chan struct{})

	// Query the wit.ai voice service asyncly.
	if err := ctx.VoiceQueryAutoAsync(func(s string) {
		r, err := witai.NewResult(s)
		if err != nil || !r.IsValid() {
			return
		}
		log.Printf("Result: %q\n", r.Outcomes[0].Text)

		// We can exit now that we have the result.
		close(done)
	}); err != nil {
		log.Fatalln("cannot query wit-ai:", err)
	}

	// Wait exiting the process until the async result returns.
	<-done
}

Installation

As simple as:

go get github.com/neurodrone/witai

witai's People

Contributors

neurodrone avatar

Watchers

James Cloos avatar  avatar

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.