piwave 2.1.1__tar.gz → 2.1.2__tar.gz
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.
- {piwave-2.1.1 → piwave-2.1.2}/PKG-INFO +1 -1
- {piwave-2.1.1 → piwave-2.1.2}/piwave/piwave.py +41 -2
- {piwave-2.1.1 → piwave-2.1.2}/piwave.egg-info/PKG-INFO +1 -1
- {piwave-2.1.1 → piwave-2.1.2}/setup.cfg +1 -1
- {piwave-2.1.1 → piwave-2.1.2}/LICENSE +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/README.md +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/__init__.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/__main__.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/backends/__init__.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/backends/base.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/backends/fm_transmitter.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/backends/pi_fm_rds.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave/logger.py +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave.egg-info/SOURCES.txt +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave.egg-info/dependency_links.txt +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave.egg-info/requires.txt +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/piwave.egg-info/top_level.txt +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/pyproject.toml +0 -0
- {piwave-2.1.1 → piwave-2.1.2}/setup.py +0 -0
|
@@ -326,6 +326,28 @@ class PiWave:
|
|
|
326
326
|
self._stop_current_process()
|
|
327
327
|
return False
|
|
328
328
|
|
|
329
|
+
def _playback_worker_wrapper(self):
|
|
330
|
+
# wrapper for non-blocking playback
|
|
331
|
+
try:
|
|
332
|
+
wav_file = self._convert_to_wav(self.current_file)
|
|
333
|
+
if not wav_file:
|
|
334
|
+
Log.error(f"Failed to convert {self.current_file}")
|
|
335
|
+
self.is_playing = False
|
|
336
|
+
return
|
|
337
|
+
|
|
338
|
+
if not os.path.exists(wav_file):
|
|
339
|
+
Log.error(f"File not found: {wav_file}")
|
|
340
|
+
self.is_playing = False
|
|
341
|
+
return
|
|
342
|
+
|
|
343
|
+
self._play_file(wav_file)
|
|
344
|
+
except Exception as e:
|
|
345
|
+
Log.error(f"Playback error: {e}")
|
|
346
|
+
if self.on_error:
|
|
347
|
+
self.on_error(e)
|
|
348
|
+
finally:
|
|
349
|
+
self.is_playing = False
|
|
350
|
+
|
|
329
351
|
|
|
330
352
|
def _play_live(self, audio_source, sample_rate: int, channels: int, chunk_size: int) -> bool:
|
|
331
353
|
if self.is_playing or self.is_live_streaming:
|
|
@@ -488,13 +510,14 @@ class PiWave:
|
|
|
488
510
|
self.stop()
|
|
489
511
|
os._exit(0)
|
|
490
512
|
|
|
491
|
-
def play(self, source, sample_rate: int = 44100, channels: int = 2, chunk_size: int = 4096):
|
|
513
|
+
def play(self, source, sample_rate: int = 44100, channels: int = 2, chunk_size: int = 4096, blocking: bool = False):
|
|
492
514
|
"""Play audio from file or live source.
|
|
493
515
|
|
|
494
516
|
:param source: Either a file path (str) or live audio source (generator/callable/file-like)
|
|
495
517
|
:param sample_rate: Sample rate for live audio (ignored for files)
|
|
496
518
|
:param channels: Channels for live audio (ignored for files)
|
|
497
519
|
:param chunk_size: Chunk size for live audio (ignored for files)
|
|
520
|
+
:param blocking: If the playback should be blocking or not (ignored for live, always non-blocking)
|
|
498
521
|
:return: True if playback/streaming started successfully
|
|
499
522
|
:rtype: bool
|
|
500
523
|
|
|
@@ -506,7 +529,23 @@ class PiWave:
|
|
|
506
529
|
# autodetect if source is live or file
|
|
507
530
|
if isinstance(source, str):
|
|
508
531
|
# file (string)
|
|
509
|
-
|
|
532
|
+
if blocking:
|
|
533
|
+
return self._play_file(source)
|
|
534
|
+
else:
|
|
535
|
+
if self.is_playing:
|
|
536
|
+
self.stop()
|
|
537
|
+
|
|
538
|
+
self.current_file = source
|
|
539
|
+
self.is_playing = True
|
|
540
|
+
self.stop_event.clear()
|
|
541
|
+
|
|
542
|
+
self.playback_thread = threading.Thread(
|
|
543
|
+
target=self._playback_worker_wrapper,
|
|
544
|
+
daemon=True
|
|
545
|
+
)
|
|
546
|
+
self.playback_thread.start()
|
|
547
|
+
return True
|
|
548
|
+
|
|
510
549
|
else:
|
|
511
550
|
# live
|
|
512
551
|
return self._play_live(source, sample_rate, channels, chunk_size)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|