-
Notifications
You must be signed in to change notification settings - Fork 31
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 #3 from deepgram-devs/new-params
added tier/replace params, updated error handling in usage, fixed opt…
- Loading branch information
Showing
10 changed files
with
244 additions
and
28 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Deepgram Devs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import ( | |
"net/http" | ||
) | ||
|
||
var sdkVersion string = "0.1.0" | ||
|
||
type Deepgram struct { | ||
ApiKey string | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
github.com/Jeffail/gabs/v2 v2.6.1 h1:wwbE6nTQTwIMsMxzi6XFQQYRZ6wDc1mSdxoAN+9U4Gk= | ||
github.com/Jeffail/gabs/v2 v2.6.1/go.mod h1:xCn81vdHKxFUuWWAaD5jCTQDNPBMh5pPs9IJ+NcziBI= | ||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= | ||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= | ||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= | ||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= | ||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,98 @@ | ||
package deepgram | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/google/go-querystring/query" | ||
"github.com/gorilla/websocket" | ||
) | ||
|
||
func (dg *Deepgram) LiveTranscription(options LiveTranscriptionOptions) (*websocket.Conn, *http.Response, error) { | ||
type PreRecordedResponse struct { | ||
Request_id string `json:"request_id"` | ||
Metadata interface{} `json:"metadata"` | ||
Results interface{} `json:"results"` | ||
} | ||
|
||
u := url.URL{Scheme: "wss", Host: "api.deepgram.com", Path: "/v1/listen",} | ||
func (dg *Deepgram) LiveTranscription(options LiveTranscriptionOptions) (*websocket.Conn, *http.Response, error) { | ||
query, _ := query.Values(options) | ||
u := url.URL{Scheme: "wss", Host: "api.deepgram.com", Path: "/v1/listen", RawQuery: query.Encode()} | ||
log.Printf("connecting to %s", u.String()) | ||
|
||
header := http.Header{ | ||
"Host": []string{"api.deepgram.com"}, | ||
"Authorization": []string{"token " + dg.ApiKey}, | ||
"X-DG-Agent": []string{"go-sdk/1.0.0"}, | ||
"X-DG-Agent": []string{"go-sdk/" + sdkVersion}, | ||
} | ||
|
||
c, resp, err := websocket.DefaultDialer.Dial(u.String(), header); | ||
|
||
if err != nil { | ||
log.Printf("handshake failed with status %d", resp.StatusCode) | ||
log.Printf("handshake failed with status %s", resp.Status) | ||
log.Fatal("dial:", err) | ||
} | ||
return c, resp, nil | ||
|
||
} | ||
|
||
func(dg *Deepgram) PreRecordedFromURL(source UrlSource, options PreRecordedTranscriptionOptions) (PreRecordedResponse, error) { | ||
client := new(http.Client) | ||
query, _ := query.Values(options) | ||
u := url.URL{Scheme: "https", Host: "api.deepgram.com", Path: "/v1/listen", RawQuery: query.Encode()} | ||
jsonStr, err := json.Marshal(source) | ||
if err != nil { | ||
log.Fatal(err) | ||
// TODO: Fix this return value | ||
return PreRecordedResponse{}, err | ||
} | ||
|
||
req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(jsonStr)) | ||
if err != nil { | ||
//Handle Error | ||
log.Fatal(err) | ||
} | ||
|
||
req.Header = http.Header{ | ||
"Host": []string{dg.Host("")}, | ||
"Content-Type": []string{"application/json"}, | ||
"Authorization": []string{"token " + dg.ApiKey}, | ||
"X-DG-Agent": []string{"go-sdk/" + sdkVersion}, | ||
} | ||
|
||
var result PreRecordedResponse | ||
res, err := client.Do(req) | ||
if err != nil { | ||
return result, err | ||
} | ||
fmt.Println("CODE:", res.Body) | ||
if res.StatusCode != 200 { | ||
b, _ := io.ReadAll(res.Body) | ||
log.Fatal(string(b)) | ||
} | ||
|
||
jsonErr := GetJson(res, &result) | ||
|
||
if jsonErr != nil { | ||
fmt.Printf("error getting request list: %s\n", jsonErr.Error()) | ||
return result, jsonErr | ||
} else { | ||
return result, nil | ||
} | ||
|
||
// query, _ := query.Values(options) | ||
// u := url.URL{Scheme: "https", Host: "api.deepgram.com", Path: "/v1/projects", RawQuery: query.Encode()} | ||
// log.Printf("connecting to %s", u.String()) | ||
|
||
// header := http.Header{ | ||
// "Host": []string{"api.deepgram.com"}, | ||
// "Authorization": []string{"token " + dg.ApiKey}, | ||
// "X-DG-Agent": []string{"go-sdk/" + sdkVersion}, | ||
// } | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package deepgram | ||
|
||
type Metadata struct { | ||
RequestId string `json:"request_id"` | ||
TransactionKey string `json:"transaction_key"` | ||
Sha256 string `json:"sha256"` | ||
Created string `json:"created"` | ||
Duration int `json:"duration"` | ||
Channels int `json:"channels"` | ||
} | ||
|
||
type Hit struct { | ||
Confidence float64 `json:"confidence"` | ||
Start float64 `json:"start"` | ||
End float64 `json:"end"` | ||
Snippet string `json:"snippet"` | ||
} | ||
|
||
type Search struct { | ||
Query string `json:"query"` | ||
Hits []Hit `json:"hits"` | ||
} | ||
|
||
type WordBase struct { | ||
Word string `json:"word"` | ||
Start float64 `json:"start"` | ||
End float64 `json:"end"` | ||
Confidence float64 `json:"confidence"` | ||
Punctuated_Word string `json:"punctuated_word"` | ||
Speaker int `json:"speaker"` | ||
} | ||
|
||
type Alternative struct { | ||
Transcript string `json:"transcript"` | ||
Confidence float64 `json:"confidence"` | ||
Words []WordBase `json:"words"` | ||
} | ||
|
||
type Channel struct { | ||
Search []Search `json:"search"` | ||
Alternatives []Alternative `json:"alternatives"` | ||
} | ||
|
||
type Utterance struct { | ||
Start float64 `json:"start"` | ||
End float64 `json:"end"` | ||
Confidence float64 `json:"confidence"` | ||
Channel int `json:"channel"` | ||
Transcript string `json:"transcript"` | ||
Words []WordBase `json:"words"` | ||
Speaker int `json:"speaker"` | ||
Id string `json:"id"` | ||
} | ||
|
||
type Results struct { | ||
Utterances []Utterance `json:"utterances"` | ||
Channels []Channel `json:"channels"` | ||
} |
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