-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from dvonthenen/expected-reconnect-failure-af…
…ter-three-attempts Expected Failure After 3 Failed Attempts
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 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,59 @@ | ||
// Copyright 2024 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 | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram/deepgram-go-sdk/pkg/client/live" | ||
) | ||
|
||
func main() { | ||
// init library | ||
client.InitWithDefault() | ||
|
||
// Go context | ||
ctx := context.Background() | ||
|
||
// set the Transcription options | ||
tOptions := &interfaces.LiveTranscriptionOptions{ | ||
Language: "en-US", | ||
Punctuate: true, | ||
} | ||
|
||
// create a Deepgram client | ||
cOptions := &interfaces.ClientOptions{ | ||
EnableKeepAlive: true, | ||
Host: "127.0.0.1", | ||
} | ||
|
||
// use the default callback handler which just dumps all messages to the screen | ||
dgClient, err := client.New(ctx, "", cOptions, tOptions, nil) | ||
if err != nil { | ||
fmt.Println("ERROR creating LiveClient connection:", err) | ||
return | ||
} | ||
|
||
// connect the websocket to Deepgram | ||
wsconn := dgClient.Connect() | ||
if wsconn == nil { | ||
fmt.Println("Client.Connect failed") | ||
os.Exit(1) | ||
} | ||
|
||
// wait for user input to exit | ||
fmt.Printf("This demonstrates using KeepAlives. Press ENTER to exit...\n") | ||
input := bufio.NewScanner(os.Stdin) | ||
input.Scan() | ||
|
||
// close client | ||
dgClient.Stop() | ||
|
||
fmt.Printf("Program exiting...\n") | ||
} |