diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/__init__.py | 13 | ||||
-rw-r--r-- | helpers/music_file.py | 7 |
2 files changed, 15 insertions, 5 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index 0e29f5d..7fe9c35 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py | |||
@@ -42,10 +42,17 @@ def parse_config(mapping): | |||
42 | if argument == 'file': | 42 | if argument == 'file': |
43 | filename = action[action_name]['file'] | 43 | filename = action[action_name]['file'] |
44 | if filename not in seen_files: | 44 | if filename not in seen_files: |
45 | if 'name' in action[action_name]: | 45 | if filename in config['music_properties']: |
46 | seen_files[filename] = MusicFile(filename, file_lock, channel_id, name = action[action_name]['name']) | 46 | seen_files[filename] = MusicFile( |
47 | filename, | ||
48 | file_lock, | ||
49 | channel_id, | ||
50 | **config['music_properties'][filename]) | ||
47 | else: | 51 | else: |
48 | seen_files[filename] = MusicFile(filename, file_lock, channel_id) | 52 | seen_files[filename] = MusicFile( |
53 | filename, | ||
54 | file_lock, | ||
55 | channel_id) | ||
49 | channel_id = channel_id + 1 | 56 | channel_id = channel_id + 1 |
50 | 57 | ||
51 | action_args['music'] = seen_files[filename] | 58 | action_args['music'] = seen_files[filename] |
diff --git a/helpers/music_file.py b/helpers/music_file.py index 667c169..892519d 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -1,13 +1,15 @@ | |||
1 | import threading | 1 | import threading |
2 | import pydub | 2 | import pydub |
3 | import pygame | 3 | import pygame |
4 | import math | ||
4 | 5 | ||
5 | class MusicFile: | 6 | class MusicFile: |
6 | def __init__(self, filename, lock, channel_id, name = None): | 7 | def __init__(self, filename, lock, channel_id, name = None, gain = 1): |
7 | self.filename = filename | 8 | self.filename = filename |
8 | self.channel_id = channel_id | 9 | self.channel_id = channel_id |
9 | self.name = name or filename | 10 | self.name = name or filename |
10 | self.raw_data = None | 11 | self.raw_data = None |
12 | self.gain = gain | ||
11 | 13 | ||
12 | self.loaded = False | 14 | self.loaded = False |
13 | self.flag_paused = False | 15 | self.flag_paused = False |
@@ -16,7 +18,8 @@ class MusicFile: | |||
16 | def load_sound(self, lock): | 18 | def load_sound(self, lock): |
17 | lock.acquire() | 19 | lock.acquire() |
18 | print("Loading « {} »".format(self.name)) | 20 | print("Loading « {} »".format(self.name)) |
19 | audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100) | 21 | volume_factor = 20 * math.log10(self.gain) |
22 | audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(44100).apply_gain(volume_factor) | ||
20 | self.sound_duration = audio_segment.duration_seconds | 23 | self.sound_duration = audio_segment.duration_seconds |
21 | self.raw_data = audio_segment.raw_data | 24 | self.raw_data = audio_segment.raw_data |
22 | print("Loaded « {} »".format(self.name)) | 25 | print("Loaded « {} »".format(self.name)) |