Skip to content

Commit

Permalink
Remove Null Fields from Response Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvonthenen committed Feb 1, 2024
1 parent 536173d commit d25bf81
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 72 deletions.
104 changes: 104 additions & 0 deletions examples/streaming/test/main.go
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)

}
36 changes: 18 additions & 18 deletions pkg/api/analyze/v1/interfaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type TopicsInfo struct {
}

type Metadata struct {
RequestID string `json:"request_id,omitempty"`
Created string `json:"created,omitempty"`
Language string `json:"language,omitempty"`
IntentsInfo IntentsInfo `json:"intents_info,omitempty"`
SentimentInfo SentimentInfo `json:"sentiment_info,omitempty"`
SummaryInfo SummaryInfo `json:"summary_info,omitempty"`
TopicsInfo TopicsInfo `json:"topics_info,omitempty"`
RequestID string `json:"request_id,omitempty"`
Created string `json:"created,omitempty"`
Language string `json:"language,omitempty"`
IntentsInfo *IntentsInfo `json:"intents_info,omitempty"`
SentimentInfo *SentimentInfo `json:"sentiment_info,omitempty"`
SummaryInfo *SummaryInfo `json:"summary_info,omitempty"`
TopicsInfo *TopicsInfo `json:"topics_info,omitempty"`
}

type Average struct {
Expand All @@ -61,13 +61,13 @@ type Intent struct {
}

type Segment struct {
Text string `json:"text,omitempty"`
StartWord int `json:"start_word,omitempty"`
EndWord int `json:"end_word,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
Topics []Topic `json:"topics,omitempty"`
Intents []Intent `json:"intents,omitempty"`
Text string `json:"text,omitempty"`
StartWord int `json:"start_word,omitempty"`
EndWord int `json:"end_word,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
Topics *[]Topic `json:"topics,omitempty"`
Intents *[]Intent `json:"intents,omitempty"`
}

type Sentiments struct {
Expand All @@ -84,10 +84,10 @@ type Intents struct {
}

type Results struct {
Sentiments Sentiments `json:"sentiments,omitempty"`
Summary Summary `json:"summary,omitempty"`
Topics Topics `json:"topics,omitempty"`
Intents Intents `json:"intents,omitempty"`
Sentiments *Sentiments `json:"sentiments,omitempty"`
Summary *Summary `json:"summary,omitempty"`
Topics *Topics `json:"topics,omitempty"`
Intents *Intents `json:"intents,omitempty"`
}

/***********************************/
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/live/v1/interfaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Word struct {
PunctuatedWord string `json:"punctuated_word,omitempty"`
Start float64 `json:"start,omitempty"`
Word string `json:"word,omitempty"`
Speaker int `json:"speaker,omitempty"`
Speaker *int `json:"speaker,omitempty"`
}

// Alternative is a single alternative in a transcript
Expand Down
106 changes: 53 additions & 53 deletions pkg/api/prerecorded/v1/interfaces/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ type Metadata struct {
Channels int `json:"channels,omitempty"`
Models []string `json:"models,omitempty"`
ModelInfo map[string]ModelInfo `json:"model_info,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
SummaryInfo SummaryInfo `json:"summary_info,omitempty"`
IntentsInfo IntentsInfo `json:"intents_info,omitempty"`
SentimentInfo SentimentInfo `json:"sentiment_info,omitempty"`
TopicsInfo TopicsInfo `json:"topics_info,omitempty"`
Warnings *[]Warning `json:"warnings,omitempty"`
SummaryInfo *SummaryInfo `json:"summary_info,omitempty"`
IntentsInfo *IntentsInfo `json:"intents_info,omitempty"`
SentimentInfo *SentimentInfo `json:"sentiment_info,omitempty"`
TopicsInfo *TopicsInfo `json:"topics_info,omitempty"`
Extra map[string]string `json:"extra,omitempty"`
}

Expand All @@ -73,15 +73,15 @@ type Search struct {
}

type Word struct {
Word string `json:"word,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Speaker int `json:"speaker,omitempty"`
SpeakerConfidence float64 `json:"speaker_confidence,omitempty"`
PunctuatedWord string `json:"punctuated_word,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
Word string `json:"word,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Speaker *int `json:"speaker,omitempty"`
SpeakerConfidence *float64 `json:"speaker_confidence,omitempty"`
PunctuatedWord string `json:"punctuated_word,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
}

type Translation struct {
Expand All @@ -90,13 +90,13 @@ type Translation struct {
}

type Alternative struct {
Transcript string `json:"transcript,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Words []Word `json:"words,omitempty"`
Paragraphs Paragraph `json:"paragraphs,omitempty"`
Entities []Entity `json:"entities,omitempty"`
Summaries []SummaryV1 `json:"summaries,omitempty"`
Translation Translation `json:"translation,omitempty"`
Transcript string `json:"transcript,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Words []Word `json:"words,omitempty"`
Paragraphs *Paragraphs `json:"paragraphs,omitempty"`
Entities *[]Entity `json:"entities,omitempty"`
Summaries *[]SummaryV1 `json:"summaries,omitempty"`
Translation *Translation `json:"translation,omitempty"`
}

type Paragraphs struct {
Expand All @@ -109,16 +109,16 @@ type Paragraph struct {
NumWords int `json:"num_words,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
}

type Sentence struct {
Text string `json:"text,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
Text string `json:"text,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
}

type Entity struct {
Expand All @@ -130,23 +130,23 @@ type Entity struct {
}

type Channel struct {
Search []Search `json:"search,omitempty"`
Search *[]Search `json:"search,omitempty"`
Alternatives []Alternative `json:"alternatives,omitempty"`
DetectedLanguage string `json:"detected_language,omitempty"`
LanguageConfidence float64 `json:"language_confidence,omitempty"`
}

type Utterance struct {
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Channel int `json:"channel,omitempty"`
Transcript string `json:"transcript,omitempty"`
Words []Word `json:"words,omitempty"`
Speaker int `json:"speaker,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
ID string `json:"id,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Channel int `json:"channel,omitempty"`
Transcript string `json:"transcript,omitempty"`
Words []Word `json:"words,omitempty"`
Speaker *int `json:"speaker,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
ID string `json:"id,omitempty"`
}

type Intent struct {
Expand All @@ -165,13 +165,13 @@ type Topic struct {
}

type Segment struct {
Text string `json:"text,omitempty"`
StartWord int `json:"start_word,omitempty"`
EndWord int `json:"end_word,omitempty"`
Sentiment string `json:"sentiment,omitempty"`
SentimentScore float64 `json:"sentiment_score,omitempty"`
Topics []Topic `json:"topics,omitempty"`
Intents []Intent `json:"intents,omitempty"`
Text string `json:"text,omitempty"`
StartWord int `json:"start_word,omitempty"`
EndWord int `json:"end_word,omitempty"`
Sentiment *string `json:"sentiment,omitempty"`
SentimentScore *float64 `json:"sentiment_score,omitempty"`
Topics *[]Topic `json:"topics,omitempty"`
Intents *[]Intent `json:"intents,omitempty"`
}

type Sentiments struct {
Expand Down Expand Up @@ -203,17 +203,17 @@ type Summary SummaryV2 // internal reference to old name
type Result struct {
Channels []Channel `json:"channels,omitempty"`
Utterances []Utterance `json:"utterances,omitempty"`
Summary SummaryV2 `json:"summary,omitempty"`
Sentiments Sentiments `json:"sentiments,omitempty"`
Topics Topics `json:"topics,omitempty"`
Intents Intents `json:"intents,omitempty"`
Summary *SummaryV2 `json:"summary,omitempty"`
Sentiments *Sentiments `json:"sentiments,omitempty"`
Topics *Topics `json:"topics,omitempty"`
Intents *Intents `json:"intents,omitempty"`
}

/***********************************/
// response/result structs
/***********************************/
type PreRecordedResponse struct {
RequestID string `json:"request_id,omitempty"` // for ?callback=...
Metadata Metadata `json:"metadata,omitempty"`
Results Result `json:"results,omitempty"`
RequestID string `json:"request_id,omitempty"` // for ?callback=...
Metadata *Metadata `json:"metadata,omitempty"`
Results *Result `json:"results,omitempty"`
}

0 comments on commit d25bf81

Please sign in to comment.