2727import sys
2828import threading
2929import time
30+ import io
3031from ..types import snowflake
3132
3233from .errors import SinkException
@@ -125,9 +126,7 @@ class AudioData:
125126 """
126127
127128 def __init__ (self , file ):
128- self .file = open (file , "ab" )
129- self .dir_path = os .path .split (file )[0 ]
130-
129+ self .file = file
131130 self .finished = False
132131
133132 def write (self , data ):
@@ -141,16 +140,12 @@ def write(self, data):
141140 def cleanup (self ):
142141 if self .finished :
143142 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 )
146144 self .finished = True
147145
148146 def on_format (self , encoding ):
149147 if not self .finished :
150148 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 )
154149
155150
156151class Sink (Filters ):
@@ -169,13 +164,8 @@ class Sink(Filters):
169164 finished_callback,
170165 ctx.channel,
171166 )
172-
173- .. versionadded:: 2.1
174167
175- Parameters
176- ----------
177- output_path: :class:`string`
178- A path to where the audio files should be output.
168+ .. versionadded:: 2.1
179169
180170 Raises
181171 ------
@@ -184,12 +174,11 @@ class Sink(Filters):
184174 Audio may only be formatted after recording is finished.
185175 """
186176
187- def __init__ (self , * , output_path = "" , filters = None ):
177+ def __init__ (self , * , filters = None ):
188178 if filters is None :
189179 filters = default_filters
190180 self .filters = filters
191181 Filters .__init__ (self , ** self .filters )
192- self .file_path = output_path
193182 self .vc = None
194183 self .audio_data = {}
195184
@@ -200,8 +189,7 @@ def init(self, vc): # called under listen
200189 @Filters .container
201190 def write (self , data , user ):
202191 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 ()
205193 self .audio_data .update ({user : AudioData (file )})
206194
207195 file = self .audio_data [user ]
@@ -215,8 +203,8 @@ def cleanup(self):
215203
216204 def get_all_audio (self ):
217205 """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+
220208 def get_user_audio (self , user : snowflake .Snowflake ):
221209 """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