-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
71 lines (60 loc) · 1.97 KB
/
server.js
File metadata and controls
71 lines (60 loc) · 1.97 KB
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
68
69
70
71
// const deepgram = new Deepgram(process.env.NEXT_PUBLIC_DEEPGRAM_API)
// const ably = new Ably.Realtime(process.env.NEXT_PUBLIC_ABLY_API)
// const fromClientChannel = ably.channels.get('request-channel')
// const broadcastChannel = ably.channels.get('broadcast-channel')
// fromClientChannel.presence.subscribe('enter', (member) => {
// console.log('New member joined: ' + member.clientId)
// // Start up Deepgram session
// const deepgramLive = deepgram.transcription.live({
// punctuate: true,
// smart_format: true,
// })
// // Start sending audio to Deepgram
// deepgramLive.addListener('transcriptReceived', (transcription) => {
// // Publish the transcript to Ably for the clients to receive
// const data = JSON.parse(transcription)
// if (data.channel == null) return
// const transcript = data.channel.alternatives[0].transcript
// if (transcript) {
// broadcastChannel.publish(member.clientId, transcript)
// }
// })
// deepgramLive.addListener('error', (err) => {
// console.log(err)
// })
// deepgramLive.addListener('close', (closeMsg) => {
// console.log('Connection closed')
// })
// // Listen to clients via Ably for audio messages
// const queue = []
// fromClientChannel.subscribe(member.clientId, (msg) => {
// if (deepgramLive.getReadyState() === 1) {
// if (queue.length > 0) {
// queue.forEach((data) => {
// deepgramLive.send(data)
// })
// queue.length = 0
// }
// deepgramLive.send(msg.data)
// } else {
// queue.push(msg.data)
// }
// })
// })
// fromClientChannel.presence.subscribe('leave', (member) => {
// console.log('Member left: ' + member.clientId)
// })
// const queue = []
// fromClientChannel.subscribe(member.clientId, (msg) => {
// if (deepgramLive.getReadyState() === 1) {
// if (queue.length > 0) {
// queue.forEach((data) => {
// deepgramLive.send(data)
// })
// queue.length = 0
// }
// deepgramLive.send(msg.data)
// } else {
// queue.push(msg.data)
// }
// })