-
Notifications
You must be signed in to change notification settings - Fork 28
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 #26 from deepgram-devs/adding-toSRT-and-WebVTT
Adding to srt and web vtt
- Loading branch information
Showing
4 changed files
with
122 additions
and
35 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
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,58 +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"` | ||
RequestId string `json:"request_id"` | ||
TransactionKey string `json:"transaction_key"` | ||
Sha256 string `json:"sha256"` | ||
Created string `json:"created"` | ||
Duration float64 `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"` | ||
Start float64 `json:"start"` | ||
End float64 `json:"end"` | ||
Snippet string `json:"snippet"` | ||
} | ||
|
||
type Search struct { | ||
Query string `json:"query"` | ||
Hits []Hit `json:"hits"` | ||
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"` | ||
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"` | ||
Transcript string `json:"transcript"` | ||
Confidence float64 `json:"confidence"` | ||
Words []WordBase `json:"words"` | ||
} | ||
|
||
type Channel struct { | ||
Search []Search `json:"search"` | ||
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"` | ||
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"` | ||
} | ||
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
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/deepgram-devs/go-sdk/deepgram" | ||
) | ||
|
||
func main() { | ||
dg := deepgram.NewClient("YOUR_API_KEY") | ||
// Feel free to use this as your audio url to test https://anchor.fm/s/3e9db190/podcast/play/22624519/https%3A%2F%2Fd3ctxlq1ktw2nl.cloudfront.net%2Fstaging%2F2020-10-15%2F128822202-44100-1-79cab5de0d7af3c9.mp3 | ||
res, err := dg.PreRecordedFromURL(deepgram.UrlSource{Url: "AUDIO_FILE_URL"}, deepgram.PreRecordedTranscriptionOptions{Punctuate: true, Diarize: true, Language: "en-US", Utterances: true}) | ||
if err != nil { | ||
fmt.Println("ERROR", err) | ||
return | ||
} | ||
// Log the results | ||
log.Printf("recv: %+v", res.Results) | ||
f, err := os.Create("transcription.vtt") | ||
if err != nil { | ||
fmt.Printf("error creating VTT file: %v", err) | ||
} | ||
// Convert the results to WebVTT format | ||
vtt, err := res.ToWebVTT() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
f.WriteString(vtt) | ||
|
||
// Convert the results to SRT format | ||
srtF, err := os.Create("transcription.srt") | ||
if err != nil { | ||
fmt.Printf("error creating SRT file: %v", err) | ||
} | ||
srt, err := res.ToSRT() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
srtF.WriteString(srt) | ||
|
||
} |