transcribesvc

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

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

Go to latest
Published: Nov 19, 2017 License: MIT Imports: 5 Imported by: 0

README

Transcription service

Go Report Card

Transcribe audio file using Google Speech API

See examples_test.go for a demo

To make sample file on Mac you can use these steps:

  • QuickTime to record new audio.m4a
  • brew install ffmpeg
  • ffmpeg -i audio.m4a -c:a flac -ac 1 audio.flac

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transcribe

func Transcribe(ctx context.Context, data []byte,
	encoding speech.RecognitionConfig_AudioEncoding,
	sampleRate int32, langLocale string) (string, error)

Transcribe runs audio file agains Google Speech service and returns a top translation alternative

Example
package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"
	"time"

	svc "github.com/antontsv/transcribesvc"
	speech "github.com/google/go-genproto/googleapis/cloud/speech/v1"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancel()
	file := "samples/audio.flac"
	data, err := ioutil.ReadFile(file)
	if err != nil {
		log.Fatalf("cannot read sample file: %v", err)
	}
	res, err := svc.Transcribe(ctx, data, speech.RecognitionConfig_FLAC, 44100, "en-US")
	if err != nil {
		log.Fatalf("cannot transcribe: %v", err)
	}
	fmt.Println(res)
}
Output:

hello Google

Types

This section is empty.

Jump to

Keyboard shortcuts

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