-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restores the VTT/SRT, Fixes Comments, and etc
- Loading branch information
dvonthenen
committed
Nov 29, 2023
1 parent
ff71f5b
commit b4eddfe
Showing
32 changed files
with
149 additions
and
144 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
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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
// // 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 | ||
|
||
/* | ||
This package provides the types for the Deepgram PreRecorded API. | ||
*/ | ||
package interfaces | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// ToWebVTT implements output for VTT | ||
func (resp *PreRecordedResponse) ToWebVTT() (string, error) { | ||
if resp.Results.Utterances == nil { | ||
return "", errors.New("this function requires a transcript that was generated with the utterances feature") | ||
} | ||
|
||
vtt := "WEBVTT\n\n" | ||
vtt += "NOTE\nTranscription provided by Deepgram\nRequest ID: " + resp.Metadata.RequestID + "\nCreated: " + resp.Metadata.Created + "\n\n" | ||
|
||
for i, utterance := range resp.Results.Utterances { | ||
utterance := utterance | ||
start := SecondsToTimestamp(utterance.Start) | ||
end := SecondsToTimestamp(utterance.End) | ||
vtt += fmt.Sprintf("%d\n%s --> %s\n%s\n\n", i+1, start, end, utterance.Transcript) | ||
} | ||
return vtt, nil | ||
} | ||
|
||
// ToSRT implements output for SRT | ||
func (resp *PreRecordedResponse) ToSRT() (string, error) { | ||
if resp.Results.Utterances == nil { | ||
return "", errors.New("this function requires a transcript that was generated with the utterances feature") | ||
} | ||
|
||
srt := "" | ||
|
||
for i, utterance := range resp.Results.Utterances { | ||
utterance := utterance | ||
start := SecondsToTimestamp(utterance.Start) | ||
end := SecondsToTimestamp(utterance.End) | ||
end = strings.ReplaceAll(end, ".", ",") | ||
srt += fmt.Sprintf("%d\n%s --> %s\n%s\n\n", i+1, start, end, utterance.Transcript) | ||
|
||
} | ||
return srt, nil | ||
} | ||
|
||
func SecondsToTimestamp(seconds float64) string { | ||
hours := int(seconds / 3600) | ||
minutes := int((seconds - float64(hours*3600)) / 60) | ||
seconds = seconds - float64(hours*3600) - float64(minutes*60) | ||
return fmt.Sprintf("%02d:%02d:%02.3f", hours, minutes, seconds) | ||
} | ||
|
||
func GetJson(resp *http.Response, target interface{}) error { | ||
defer resp.Body.Close() | ||
|
||
return json.NewDecoder(resp.Body).Decode(target) | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Oops, something went wrong.