-
-
Save abnercosta/06ccc56e26f836be0e36f7b6400e1d17 to your computer and use it in GitHub Desktop.
Revisions
-
Jaana Burcu Dogan revised this gist
Aug 30, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -74,11 +74,11 @@ func main() { break } if err != nil { // TODO: handle error continue } if resp.Error != nil { // TODO: handle error continue } for _, result := range resp.Results { -
Jaana Burcu Dogan revised this gist
Aug 30, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -82,7 +82,7 @@ func main() { continue } for _, result := range resp.Results { fmt.Printf("result: %+v\n", result) } } } -
Jaana Burcu Dogan revised this gist
Aug 30, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,6 +70,9 @@ func main() { for { resp, err := stream.Recv() if err == io.EOF { break } if err != nil { log.Printf("streaming response error: %v", err) continue -
Jaana Burcu Dogan created this gist
Aug 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,85 @@ // Copyright 2016 Google Inc. All rights reserved. // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. // Command caption reads an audio file and outputs the transcript for it. package main import ( "fmt" "io" "log" "os" "golang.org/x/net/context" "google.golang.org/api/option" "google.golang.org/api/transport" speech "google.golang.org/genproto/googleapis/cloud/speech/v1beta1" ) func main() { ctx := context.Background() conn, err := transport.DialGRPC(ctx, option.WithEndpoint("speech.googleapis.com:443"), option.WithScopes("https://www.googleapis.com/auth/cloud-platform"), ) if err != nil { log.Fatal(err) } defer conn.Close() stream, err := speech.NewSpeechClient(conn).StreamingRecognize(ctx) if err != nil { log.Fatal(err) } // send the initial configuration message. if err := stream.Send(&speech.StreamingRecognizeRequest{ StreamingRequest: &speech.StreamingRecognizeRequest_StreamingConfig{ StreamingConfig: &speech.StreamingRecognitionConfig{ Config: &speech.RecognitionConfig{ Encoding: speech.RecognitionConfig_LINEAR16, SampleRate: 16000, }, }, }, }); err != nil { log.Fatal(err) } go func() { // pipe stdin to the API buf := make([]byte, 1024) for { n, err := os.Stdin.Read(buf) if err == io.EOF { return // nothing else to pipe, kill this goroutine } if err != nil { log.Printf("reading stdin error: %v", err) continue } if err = stream.Send(&speech.StreamingRecognizeRequest{ StreamingRequest: &speech.StreamingRecognizeRequest_AudioContent{ AudioContent: buf[:n], }, }); err != nil { log.Printf("sending audio error: %v", err) } } }() for { resp, err := stream.Recv() if err != nil { log.Printf("streaming response error: %v", err) continue } if resp.Error != nil { log.Printf("grpc error: %v", resp.Error) continue } for _, result := range resp.Results { fmt.Printf("result: %+v", result) } } }