kenenet 0.7.8__py3-none-any.whl → 0.7.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kenenet/__init__.py CHANGED
@@ -3,6 +3,13 @@ import numpy as np
3
3
  from PIL import Image
4
4
  from pydub import AudioSegment
5
5
  from pydub.playback import play
6
+ import random
7
+ import threading
8
+ import pyaudio
9
+ import time
10
+ from pydub import AudioSegment
11
+ from zhmiscellany._processing_supportfuncs import _ray_init_thread
12
+ import zhmiscellany.processing
6
13
  global timings, ospid, debug_mode
7
14
  ospid, debug_mode = None, False
8
15
  timings = {}
@@ -187,14 +194,73 @@ def save_img(img, name=' ', reset=True, file='temp_screenshots', mute=False):
187
194
  else:
188
195
  quick_print(f"Your img is not a fucking numpy array you twat, couldn't save {name}", lineno)
189
196
 
190
- def load_audio(mp3_path):
191
- from zhmiscellany._processing_supportfuncs import _ray_init_thread; _ray_init_thread.join()
192
- return AudioSegment.from_mp3(mp3_path)
197
+
198
+ class AudioPlayer:
199
+ def __init__(self, file):
200
+ self.file = file
201
+ self.active_audio = {}
202
+
203
+ def _stream_audio(self, sound, stop_event, chunk=1024):
204
+ p = pyaudio.PyAudio()
205
+ stream = p.open(
206
+ format=p.get_format_from_width(sound.sample_width),
207
+ channels=sound.channels,
208
+ rate=sound.frame_rate,
209
+ output=True
210
+ )
211
+ raw_data = sound.raw_data
212
+ for i in range(0, len(raw_data), chunk):
213
+ if stop_event.is_set():
214
+ break
215
+ stream.write(raw_data[i:i + chunk])
216
+
217
+ stream.stop_stream()
218
+ stream.close()
219
+ p.terminate()
220
+
221
+ class _AudioLooper:
222
+ def __init__(self, sound, stop_event, stream_func, loop=True):
223
+ self.sound = sound
224
+ self.loop = loop
225
+ self.stop_event = stop_event
226
+ self.stream_func = stream_func
227
+ self.thread = threading.Thread(target=self._loop_audio, name="AudioLooperThread", daemon=True)
228
+ self.thread.start()
229
+
230
+ def _loop_audio(self):
231
+ while not self.stop_event.is_set():
232
+ self.stream_func(self.sound, self.stop_event)
233
+ if not self.loop:
234
+ break
235
+
236
+ def stop(self):
237
+ self.stop_event.set()
238
+ self.thread.join()
193
239
 
194
- def play_audio(file_sound, range=(0.9, 1.1)):
195
- sound = file_sound
196
- sound = sound._spawn(sound.raw_data, overrides={'frame_rate': int(sound.frame_rate * random.uniform(*range))})
197
- zhmiscellany.processing.multiprocess_threaded(play, (sound,))
240
+ def play(self, loop=False, range=(0.9, 1.1)):
241
+ file_sound = AudioSegment.from_mp3(self.file)._spawn(
242
+ AudioSegment.from_mp3(self.file).raw_data,
243
+ overrides={'frame_rate': int(AudioSegment.from_mp3(self.file).frame_rate * random.uniform(*range))}
244
+ )
245
+ stop_event = threading.Event()
246
+ looper = self._AudioLooper(file_sound, stop_event, self._stream_audio, loop=loop)
247
+ self.active_audio[id(file_sound)] = looper
248
+
249
+ def stop(self, file_sound=None):
250
+ if file_sound:
251
+ file_sound_id = id(file_sound)
252
+ if file_sound_id in self.active_audio:
253
+ self.active_audio[file_sound_id].stop()
254
+ del self.active_audio[file_sound_id]
255
+ else:
256
+ for looper in self.active_audio.values():
257
+ looper.stop()
258
+ self.active_audio.clear()
259
+
260
+
261
+ def load_audio(mp3_path):
262
+ _ray_init_thread.join()
263
+ return zhmiscellany.processing.synchronous_class_multiprocess(AudioPlayer, mp3_path)
198
264
 
199
265
  class k:
200
266
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kenenet
3
- Version: 0.7.8
3
+ Version: 0.7.9
4
4
  Summary: dude what the fuck even is this package
5
5
  Home-page: https://www.youtube.com/@KiddyKene
6
6
  Author: kiddykene
@@ -0,0 +1,5 @@
1
+ kenenet/__init__.py,sha256=gm2KeCvfhCSb_bytoZ8kD-F3-K-0tzswxrKkhWMEeAQ,10779
2
+ kenenet-0.7.9.dist-info/METADATA,sha256=tnQtMyZv3_uO06omh5LMmu65ecMuM0Vj-Bah_JOSQLk,633
3
+ kenenet-0.7.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
+ kenenet-0.7.9.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
+ kenenet-0.7.9.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- kenenet/__init__.py,sha256=-DshHA4EvVdFIH6XO2MqJh9_t91VODN46JNILwes9Qk,8564
2
- kenenet-0.7.8.dist-info/METADATA,sha256=Xlo3c1pscdVaRFqlAwGAj_nvNRj5xr5FAW7iqsnz93Q,633
3
- kenenet-0.7.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
- kenenet-0.7.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
- kenenet-0.7.8.dist-info/RECORD,,