Skip to content

Commit

Permalink
refactor variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kkram01 committed Jan 22, 2024
1 parent 1fe2a2c commit 7adefda
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 79 deletions.
31 changes: 0 additions & 31 deletions speech/livecaption_from_file_v2/go.mod

This file was deleted.

15 changes: 8 additions & 7 deletions speech/livecaption_from_file_v2/livecaption_from_file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,18 +19,19 @@ package main

// [START speech_transcribe_streaming]
import (
speech "cloud.google.com/go/speech/apiv2"
"cloud.google.com/go/speech/apiv2/speechpb"
"context"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"

speech "cloud.google.com/go/speech/apiv2"
"cloud.google.com/go/speech/apiv2/speechpb"
)

var project = ""
var projectID string

const location = "global"

Expand All @@ -45,7 +46,7 @@ func main() {
log.Fatal("Please pass path to your project_id and local audio file as a command line argument")
}
audioFile := flag.Arg(1)
project = flag.Arg(0)
projectID = flag.Arg(0)

ctx := context.Background()

Expand All @@ -59,7 +60,7 @@ func main() {
}
// Send the initial configuration message.
if err := stream.Send(&speechpb.StreamingRecognizeRequest{
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", project, location),
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", projectID, location),
StreamingRequest: &speechpb.StreamingRecognizeRequest_StreamingConfig{
StreamingConfig: &speechpb.StreamingRecognitionConfig{
Config: &speechpb.RecognitionConfig{
Expand Down Expand Up @@ -97,7 +98,7 @@ func main() {
n, err := f.Read(buf)
if n > 0 {
if err := stream.Send(&speechpb.StreamingRecognizeRequest{
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", project, location),
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", projectID, location),
StreamingRequest: &speechpb.StreamingRecognizeRequest_Audio{
Audio: buf[:n],
},
Expand Down
31 changes: 0 additions & 31 deletions speech/livecaption_v2/go.mod

This file was deleted.

21 changes: 11 additions & 10 deletions speech/livecaption_v2/livecaption.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,17 +23,18 @@ package main

// [START speech_transcribe_streaming_mic]
import (
speech "cloud.google.com/go/speech/apiv2"
"cloud.google.com/go/speech/apiv2/speechpb"
"context"
"flag"
"fmt"
"io"
"log"
"os"

speech "cloud.google.com/go/speech/apiv2"
"cloud.google.com/go/speech/apiv2/speechpb"
)

var project = ""
var projectID string

const location = "global"

Expand All @@ -42,17 +43,17 @@ func main() {

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s <Project_id>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "<project> must be a project_id to a valid gcp project with speech api enabled.\n")
fmt.Fprintf(os.Stderr, "<projectID> must be a project_id to a valid gcp projectID with speech api enabled.\n")

}
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatal("Please pass the project_id as a command line argument. Should be a valid project_id with stt api enabled.")
}
project = flag.Arg(0)
projectID = flag.Arg(0)

if project == "" {
log.Fatalf("Project is is required parameter: %s", project)
if projectID == "" {
log.Fatalf("Project is is required parameter: %s", projectID)
}

client, err := speech.NewClient(ctx)
Expand All @@ -65,7 +66,7 @@ func main() {
}

if err := stream.Send(&speechpb.StreamingRecognizeRequest{
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", project, location),
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", projectID, location),
StreamingRequest: &speechpb.StreamingRecognizeRequest_StreamingConfig{
StreamingConfig: &speechpb.StreamingRecognitionConfig{
Config: &speechpb.RecognitionConfig{
Expand Down Expand Up @@ -101,7 +102,7 @@ func main() {

if n > 0 {
if err := stream.Send(&speechpb.StreamingRecognizeRequest{
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", project, location),
Recognizer: fmt.Sprintf("projects/%s/locations/%s/recognizers/_", projectID, location),
StreamingRequest: &speechpb.StreamingRecognizeRequest_Audio{
Audio: buf[:n],
},
Expand Down

0 comments on commit 7adefda

Please sign in to comment.