-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Null Fields from Response Objects
- Loading branch information
1 parent
536173d
commit d25bf81
Showing
4 changed files
with
176 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2023 Deepgram SDK contributors. All Rights Reserved. | ||
// Use of this source code is governed by a MIT license that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package main | ||
|
||
// streaming | ||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
microphone "github.com/deepgram/deepgram-go-sdk/pkg/audio/microphone" | ||
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram/deepgram-go-sdk/pkg/client/live" | ||
) | ||
|
||
func main() { | ||
// init library | ||
microphone.Initialize() | ||
|
||
/* | ||
DG Streaming API | ||
*/ | ||
// init library | ||
client.Init(client.InitLib{ | ||
LogLevel: client.LogLevelDefault, // LogLevelDefault, LogLevelFull, LogLevelDebug, LogLevelTrace | ||
}) | ||
|
||
// Go context | ||
ctx := context.Background() | ||
|
||
// set the Transcription options | ||
tOptions := interfaces.LiveTranscriptionOptions{ | ||
Model: "nova-2", | ||
Language: "en-US", | ||
Punctuate: true, | ||
Encoding: "linear16", | ||
Channels: 1, | ||
SampleRate: 16000, | ||
SmartFormat: true, | ||
} | ||
|
||
// create a Deepgram client | ||
dgClient, err := client.NewForDemo(ctx, tOptions) | ||
if err != nil { | ||
fmt.Println("ERROR creating LiveTranscription connection:", err) | ||
return | ||
} | ||
|
||
// connect the websocket to Deepgram | ||
wsconn := dgClient.Connect() | ||
if wsconn == nil { | ||
fmt.Println("Client.Connect failed") | ||
os.Exit(1) | ||
} | ||
|
||
/* | ||
Microphone package | ||
*/ | ||
// mic stuf | ||
mic, err := microphone.New(microphone.AudioConfig{ | ||
InputChannels: 1, | ||
SamplingRate: 16000, | ||
}) | ||
if err != nil { | ||
fmt.Printf("Initialize failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// start the mic | ||
err = mic.Start() | ||
if err != nil { | ||
fmt.Printf("mic.Start failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
go func() { | ||
// feed the microphone stream to the Deepgram client (this is a blocking call) | ||
mic.Stream(dgClient) | ||
}() | ||
|
||
fmt.Print("Press ENTER to exit!\n\n") | ||
input := bufio.NewScanner(os.Stdin) | ||
input.Scan() | ||
|
||
// close mic stream | ||
err = mic.Stop() | ||
if err != nil { | ||
fmt.Printf("mic.Stop failed. Err: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// teardown library | ||
microphone.Teardown() | ||
|
||
// close DG client | ||
dgClient.Stop() | ||
|
||
fmt.Printf("Program exiting...\n") | ||
// time.Sleep(120 * time.Second) | ||
|
||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters