-
Notifications
You must be signed in to change notification settings - Fork 34
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 #34 from TrippleCCC/pre-recorded-local-file
Create function PreRecordedFromStream for transcribing local files
- Loading branch information
Showing
2 changed files
with
95 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
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,56 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/deepgram-devs/go-sdk/deepgram" | ||
) | ||
|
||
var ( | ||
key = flag.String("key", "", "Deepgram API key") | ||
file = flag.String("file", "", "Path to file that will be transcribed") | ||
mimetype = flag.String("mimetype", "", "Mimetype of file") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
dg := deepgram.NewClient(*key) | ||
file, err := os.Open(*file) | ||
if err != nil { | ||
log.Fatalf("error opening file %s: %v", *file, err) | ||
} | ||
source := deepgram.ReadStreamSource{Stream: file, Mimetype: *mimetype} | ||
res, err := dg.PreRecordedFromStream(source, 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) | ||
|
||
} |