Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
BLACK=(50, 50, 50, 255),
GREEN=(142, 219, 176, 255),
RED=(241, 100, 100, 255),
YELLOW=(255, 215, 0, 255),
BACKGROUND=(240, 240, 240, 255),
LIGHTGREY=(220, 220, 220, 255),
DARKGREY=(50, 50, 50, 255),
Expand Down
35 changes: 33 additions & 2 deletions plugins/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from string import ascii_uppercase, digits, ascii_lowercase
from math import copysign
from pathlib import Path
import wave
from pyglet.media import Player, SourceGroup, load
from plugins.abstractplugin import AbstractPlugin
from core.widgets import Radio, Simpletext
Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(self, label='', taskplacement='bottomleft', taskupdatetime=80):
self.lastradioselected = None
self.frequency_modulation = 0.1
self.sound_path = None
self._empty_sample_path = None

self.set_sample_sounds()

Expand All @@ -91,6 +93,7 @@ def set_sample_sounds(self):
return

self.sound_path = new_path
self._ensure_empty_sample()
self.samples_path = [self.sound_path.joinpath(f'{i}.wav')
for i in [s for s in digits + ascii_lowercase] +
[this_radio.lower() for this_radio in self.parameters['promptlist']] +
Expand All @@ -101,6 +104,35 @@ def set_sample_sounds(self):
print(sample_needed, _(' does not exist'))


def _ensure_empty_sample(self):
if self.sound_path is None:
return None

empty_path = self.sound_path.joinpath('empty.wav')
if empty_path.exists():
self._empty_sample_path = empty_path
return empty_path

empty_path.parent.mkdir(parents=True, exist_ok=True)
with wave.open(str(empty_path), 'wb') as silent_file:
silent_file.setnchannels(1)
silent_file.setsampwidth(2)
silent_file.setframerate(44100)
silent_file.writeframes(b'\x00\x00' * 4410)

self._empty_sample_path = empty_path
return empty_path


def _load_audio_segment(self, name):
target = self.sound_path.joinpath(f'{name}.wav')
if not target.exists():
if name != 'empty':
print(target, _(' missing, using silence instead'))
target = self._empty_sample_path or self._ensure_empty_sample()
return load(str(target), streaming=False)


def regenerate_callsigns(self):
self.parameters['owncallsign'] = self.get_callsign()
for i in range(self.parameters['othercallsignnumber']):
Expand Down Expand Up @@ -157,8 +189,7 @@ def group_audio_files(self, callsign, radio_name, freq):

group = SourceGroup()
for f in list_of_sounds:
source = load(str(self.sound_path.joinpath(f'{f}.wav')), streaming=False)
# print(f)
source = self._load_audio_segment(f)
group.add(source)
return group

Expand Down
Loading