Skip to content

Commit

Permalink
Merge pull request #231 from dvonthenen/expected-reconnect-failure-af…
Browse files Browse the repository at this point in the history
…ter-three-attempts

Expected Failure After 3 Failed Attempts
  • Loading branch information
dvonthenen authored May 31, 2024
2 parents 2479aa6 + 9fd2983 commit af4d231
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/edge_cases/failed_retry/main.go
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")
}

0 comments on commit af4d231

Please sign in to comment.