-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscript.go
48 lines (44 loc) · 1.68 KB
/
transcript.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"io"
"log"
)
// Define a struct to handle different Speech-to-Text providers
type SpeechToTextProvider struct {
GoogleClient func(ctx context.Context, audioStream io.Reader, callUUID string)
DeepgramClient func(ctx context.Context, audioStream io.Reader, callUUID string) error
OpenAIClient func(ctx context.Context, audioStream io.Reader, callUUID string) error
}
// StreamToProvider is a generic function to stream audio to the desired provider
func StreamToProvider(ctx context.Context, provider string, audioStream io.Reader, callUUID string) {
switch provider {
case "google":
if speechToText.GoogleClient != nil {
log.Printf("Starting transcription using Google for call: %s", callUUID)
speechToText.GoogleClient(ctx, audioStream, callUUID)
} else {
log.Printf("Google Speech-to-Text client not initialized for call: %s", callUUID)
}
case "deepgram":
if err := speechToText.DeepgramClient(ctx, audioStream, callUUID); err != nil {
log.Printf("Deepgram transcription failed for call %s: %v", callUUID, err)
} else {
log.Printf("Deepgram transcription completed for call: %s", callUUID)
}
case "openai":
if err := speechToText.OpenAIClient(ctx, audioStream, callUUID); err != nil {
log.Printf("OpenAI transcription failed for call %s: %v", callUUID, err)
} else {
log.Printf("OpenAI transcription completed for call: %s", callUUID)
}
default:
log.Printf("Unknown provider '%s' for call: %s", provider, callUUID)
}
}
// Define a global variable for the SpeechToTextProvider
var speechToText = SpeechToTextProvider{
GoogleClient: streamToGoogleSpeech,
DeepgramClient: streamToDeepgram,
OpenAIClient: streamToOpenAI,
}