-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathstreamingSink.py
55 lines (45 loc) · 1.56 KB
/
streamingSink.py
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
import io
from discord.sinks.core import Filters, Sink, default_filters, AudioData
class StreamingSink(Sink):
"""A custom sink that will convert the audio to
"""
def __init__(self, signals, stt, filters=None):
if filters is None:
filters = default_filters
self.filters = filters
Filters.__init__(self, **self.filters)
self.encoding = "pcm"
self.vc = None
self.audio_data = {}
self.signals = signals
self.stt = stt
# Override the write method to instead stream the audio elsewhere
@Filters.container
def write(self, data, user):
print("Receiving voice")
if user not in self.audio_data:
file = io.BytesIO()
self.audio_data.update({user: AudioData(file)})
file = self.audio_data[user]
file.write(data)
# # Save sound data to AudioSegment object
# sound = AudioSegment(
# # raw audio data (bytes)
# data=data,
# # 2 byte (16 bit) samples
# sample_width=2,
# # 48 kHz frame rate
# frame_rate=48000,
# # stereo
# channels=2
# )
# # Convert sound to mono
# sound = sound.set_channels(1)
# # Convert sound to 16khz
# sound = sound.set_frame_rate(16000)
# # Send the 16bit 16khz mono PCM audio data to STT
# if self.signals.stt_ready:
# self.stt.feed_audio(sound.raw_data)
# print("FEEDING AUDIO")
def format_audio(self, audio):
return