speech

package module
v0.0.0-...-d52bb95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2017 License: MIT Imports: 13 Imported by: 0

README

Speech to Text

IBM Bluemix, the Speech to Text service converts the human voice into the written word.

Install

go get github.com/nuveo/speech-to-text

Export to env SPEECH_USERNAME and SPEECH_PASSWORD.

credentials getting in dashboard

Usage

bin
cd $GOPATH/src/github.com/nuveo/speech-to-text/speech
go build
./speech -input /path/to/audio/file
Code
package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/nuveo/speech-to-text"
)

var (
	inputFile = flag.String("input", "", "File to convert into text")
)

func main() {
	flag.Parse()

	if *inputFile != "" {
		c := speech.Credentials{}
		c.Setup()

		url := c.MakeSessionURL()
		sess, err := speech.GetSession(url)
		if err != nil {
			return
		}

		status, err := sess.GetRecognize()
		if err != nil {
			return
		}

		if status.Session.State != "initialized" {
			log.Println("Not ready yet, got:", status.Session.State)
			return
		}

		text, err := sess.SendAudio(*inputFile)
		if err != nil {
			return
		}

		fmt.Println(text)
		sess.DeleteSession()
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToWav

func ConvertToWav(path string) (string, error)

ConvertToWav convert files mp3 to Wav

func SetSessionModel

func SetSessionModel(m string)

Types

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Session  string `json:"session"`
}

Credentials is struct to save informations api

func (*Credentials) MakeSessionURL

func (c *Credentials) MakeSessionURL() string

MakeSessionURL Getting session url with username and password environments

func (*Credentials) Setup

func (c *Credentials) Setup()

Setup !

type ErrorResponse

type ErrorResponse struct {
	Error           string `json:"error"`
	CodeDescription string `json:"code_description"`
}

ErrorResponse struct of errors

type RecognizeBody

type RecognizeBody struct {
	State         string `json:"state"`
	Model         string `json:"model"`
	Recognize     string `json:"recognize"`
	ObserveResult string `json:"observe_result"`
}

RecognizeBody body response

type RecognizeResponse

type RecognizeResponse struct {
	ResultIndex int      `json:"result_index"`
	Results     []Result `json:"results"`
}

RecognizeResponse strct

type RecognizeStatus

type RecognizeStatus struct {
	Session RecognizeBody `json:"session"`
}

RecognizeStatus Get status from /recgonize api. checks that Speech-to-text api is available for new recognition

type Result

type Result struct {
	Final        bool                     `json:"final"`
	Alternatives []map[string]interface{} `json:"alternatives"`
}

Result strct

type SessionRsp

type SessionRsp struct {
	SessionID     string `json:"session_id"`
	NewSessionURI string `json:"new_session_uri"`
	Recognize     string `json:"recognize"`
	ObserveResult string `json:"observe_result"`
	CJar          *cookiejar.Jar
}

SessionRsp is struct to save session informations from request

func GetSession

func GetSession(sessionURL string) (SessionRsp, error)

GetSession <-

func (*SessionRsp) DeleteSession

func (s *SessionRsp) DeleteSession() error

DeleteSession remove session

func (*SessionRsp) GetRecognize

func (s *SessionRsp) GetRecognize() (RecognizeStatus, error)

GetRecognize -<

func (*SessionRsp) ObserverResult

func (s *SessionRsp) ObserverResult() error

ObserverResult <-

func (*SessionRsp) SendAudio

func (s *SessionRsp) SendAudio(pathAudio string) (string, error)

SendAudio blah

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL