27
27
import sys
28
28
import threading
29
29
import time
30
+ import io
30
31
from ..types import snowflake
31
32
32
33
from .errors import SinkException
@@ -125,9 +126,7 @@ class AudioData:
125
126
"""
126
127
127
128
def __init__ (self , file ):
128
- self .file = open (file , "ab" )
129
- self .dir_path = os .path .split (file )[0 ]
130
-
129
+ self .file = file
131
130
self .finished = False
132
131
133
132
def write (self , data ):
@@ -141,16 +140,12 @@ def write(self, data):
141
140
def cleanup (self ):
142
141
if self .finished :
143
142
raise SinkException ("The AudioData is already finished writing." )
144
- self .file .close ()
145
- self .file = os .path .join (self .dir_path , self .file .name )
143
+ self .file .seek (0 )
146
144
self .finished = True
147
145
148
146
def on_format (self , encoding ):
149
147
if not self .finished :
150
148
raise SinkException ("The AudioData is still writing." )
151
- name = os .path .split (self .file )[1 ]
152
- name = name .split ("." )[0 ] + f".{ encoding } "
153
- self .file = os .path .join (self .dir_path , name )
154
149
155
150
156
151
class Sink (Filters ):
@@ -169,13 +164,8 @@ class Sink(Filters):
169
164
finished_callback,
170
165
ctx.channel,
171
166
)
172
-
173
- .. versionadded:: 2.1
174
167
175
- Parameters
176
- ----------
177
- output_path: :class:`string`
178
- A path to where the audio files should be output.
168
+ .. versionadded:: 2.1
179
169
180
170
Raises
181
171
------
@@ -184,12 +174,11 @@ class Sink(Filters):
184
174
Audio may only be formatted after recording is finished.
185
175
"""
186
176
187
- def __init__ (self , * , output_path = "" , filters = None ):
177
+ def __init__ (self , * , filters = None ):
188
178
if filters is None :
189
179
filters = default_filters
190
180
self .filters = filters
191
181
Filters .__init__ (self , ** self .filters )
192
- self .file_path = output_path
193
182
self .vc = None
194
183
self .audio_data = {}
195
184
@@ -200,8 +189,7 @@ def init(self, vc): # called under listen
200
189
@Filters .container
201
190
def write (self , data , user ):
202
191
if user not in self .audio_data :
203
- ssrc = self .vc .get_ssrc (user )
204
- file = os .path .join (self .file_path , f"{ ssrc } .pcm" )
192
+ file = io .BytesIO ()
205
193
self .audio_data .update ({user : AudioData (file )})
206
194
207
195
file = self .audio_data [user ]
@@ -215,8 +203,8 @@ def cleanup(self):
215
203
216
204
def get_all_audio (self ):
217
205
"""Gets all audio files."""
218
- return [os . path . realpath ( x .file ) for x in self .audio_data .values ()]
219
-
206
+ return [x .file for x in self .audio_data .values ()]
207
+
220
208
def get_user_audio (self , user : snowflake .Snowflake ):
221
209
"""Gets the audio file(s) of one specific user."""
222
- return os .path .realpath (self .audio_data .pop (user ))
210
+ return os .path .realpath (self .audio_data .pop (user ))
0 commit comments