-
Notifications
You must be signed in to change notification settings - Fork 32
/
Program.cs
67 lines (57 loc) · 2.26 KB
/
Program.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2024 Deepgram .NET 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
using Deepgram.Models.Listen.v2.WebSocket;
namespace SampleApp
{
class Program
{
static async Task Main(string[] args)
{
try
{
// Initialize Library with default logging
// Normal logging is "Info" level
Library.Initialize();
// use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable
var liveClient = ClientFactory.CreateListenWebSocketClient();
// Subscribe to the EventResponseReceived event
await liveClient.Subscribe(new EventHandler<ResultResponse>((sender, e) =>
{
if (e.Channel.Alternatives[0].Transcript == "")
{
return;
}
// Console.WriteLine("Transcription received: " + JsonSerializer.Serialize(e.Transcription));
Console.WriteLine($"\n\n\nSpeaker: {e.Channel.Alternatives[0].Transcript}\n\n\n");
}));
// Start the connection
var liveSchema = new LiveSchema()
{
Model = "nova-2",
Punctuate = true,
SmartFormat = true,
};
bool bConnected = await liveClient.Connect(liveSchema);
if (!bConnected)
{
Console.WriteLine("Failed to connect to the server");
return;
}
// Send some audio data
var audioData = File.ReadAllBytes(@"preamble.wav");
liveClient.Send(audioData);
// Wait for a while to receive responses
await Task.Delay(45000);
// Stop the connection
await liveClient.Stop();
// Teardown Library
Library.Terminate();
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
}
}
}
}