Skip to content

Commit 0977b20

Browse files
author
arch
committed
add notification sound
1 parent 4e02c8d commit 0977b20

File tree

9 files changed

+30
-2
lines changed

9 files changed

+30
-2
lines changed

docs/app/docs/user-guide/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Config Files:
2525
- `max_playback_fps` (int): Limit the max player speed in the tracking preview window (0 = disable limit)
2626
- `preview_scaling` (float): Set the preview image scaling factor. With a value of `1.0`, the window should fill the height or width of the screen depending on the aspect ratio of the video.
2727
- `tracker`: (str) Specify the tracker algorithm. Available options are `'MIL'`, `'KCF'`, `'CSRT'`.
28+
- `notification_sound` (str) Specify the wav file to play when tracking finished (write 'off' to disable the sound notification).
2829

2930
#### `hyperparameter.yaml`
3031

environment_appimage.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ dependencies:
160160
- matplotlib==3.4.2
161161
- mergedeep==1.3.4
162162
- mkdocs==1.2.1
163+
- playsound==1.3.0
163164
- pyinstaller==4.3
164165
- pyinstaller-hooks-contrib==2021.2
165166
- pynput==1.7.3

environment_ubuntu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ dependencies:
160160
- matplotlib==3.4.2
161161
- mergedeep==1.3.4
162162
- mkdocs==1.2.1
163+
- playsound==1.3.0
163164
- pyinstaller==4.3
164165
- pyinstaller-hooks-contrib==2021.2
165166
- pynput==1.7.3

environment_windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dependencies:
6262
- opencv-contrib-python==4.5.2.54
6363
- packaging==21.0
6464
- pefile==2021.5.24
65+
- playsound==1.3.0
6566
- pyinstaller==4.3
6667
- pyinstaller-hooks-contrib==2021.2
6768
- pynput==1.7.3

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
""" Top level process to generate the funscript actions by tracking selected features in the video """
22

33
import cv2
4+
import os
45
import copy
56
import time
67
import math
78
import json
89
import logging
10+
import threading
911

12+
from playsound import playsound
1013
from screeninfo import get_monitors
1114
from queue import Queue
1215
from pynput.keyboard import Key, Listener
@@ -20,7 +23,7 @@
2023
from funscript_editor.algorithms.videotracker import StaticVideoTracker
2124
from funscript_editor.data.ffmpegstream import FFmpegStream
2225
from funscript_editor.data.funscript import Funscript
23-
from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS, PROJECTION
26+
from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS, PROJECTION, NOTIFICATION_SOUND_FILE
2427
from funscript_editor.utils.logging import get_logfiles_paths
2528
from funscript_editor.definitions import SETTINGS_CONFIG_FILE, HYPERPARAMETER_CONFIG_FILE
2629

@@ -278,6 +281,8 @@ def min_max_selector(self,
278281
cv2.putText(image, "Use 'space' to quit and set the trackbar values",
279282
(self.x_text_start, 100), cv2.FONT_HERSHEY_SIMPLEX, self.font_size, (255,0,0), 2)
280283

284+
beep_thread = threading.Thread(target=self.beep)
285+
beep_thread.start()
281286
self.clear_keypress_queue()
282287
trackbarValueMin = lower_limit
283288
trackbarValueMax = upper_limit
@@ -298,6 +303,15 @@ def min_max_selector(self,
298303
return (trackbarValueMin, trackbarValueMax) if trackbarValueMin < trackbarValueMax else (trackbarValueMax, trackbarValueMin)
299304

300305

306+
def beep(self) -> None:
307+
""" Play an sound to signal an event """
308+
if NOTIFICATION_SOUND_FILE is not None:
309+
if os.path.exists(NOTIFICATION_SOUND_FILE):
310+
playsound(NOTIFICATION_SOUND_FILE)
311+
else:
312+
self.logger.warning("Notification sound file not found (%s)", NOTIFICATION_SOUND_FILE)
313+
314+
301315
def calculate_score(self) -> None:
302316
""" Calculate the score for the predicted tracking boxes
303317

funscript_editor/config/settings.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ preview_scaling: 0.6
1919

2020
# Specify the tracker algorithm. Available options are 'MIL', 'KCF', 'CSRT'.
2121
tracker: 'CSRT'
22+
23+
# Specify the wav file to play when tracking finished (write 'off' to disable the sound notification)
24+
notification_sound: 'sound_notification.wav'
253 KB
Binary file not shown.

funscript_editor/data/ffmpegstream.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ def run(self) -> None:
302302
pipe = sp.Popen(
303303
command,
304304
stdout = sp.PIPE,
305+
stderr = sp.PIPE,
305306
bufsize= 3 * self.config['parameter']['height'] * self.config['parameter']['width']
306307
)
307308

@@ -327,3 +328,6 @@ def run(self) -> None:
327328
pipe.terminate()
328329
try: pipe.stdout.close()
329330
except: pass
331+
try: pipe.stderr.close()
332+
except: pass
333+

funscript_editor/utils/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import yaml
55

6-
from funscript_editor.definitions import ROOT_DIR, UI_CONFIG_FILE, \
6+
from funscript_editor.definitions import ROOT_DIR, CONFIG_DIR, UI_CONFIG_FILE, \
77
HYPERPARAMETER_CONFIG_FILE, SETTINGS_CONFIG_FILE, PROJECTION_CONFIG_FILE
88

99
def read_yaml_config(config_file: str) -> dict:
@@ -45,3 +45,6 @@ def read_version() -> str:
4545

4646
#: projection parameter
4747
PROJECTION = read_yaml_config(PROJECTION_CONFIG_FILE)
48+
49+
#: notification sound file
50+
NOTIFICATION_SOUND_FILE = os.path.join(CONFIG_DIR, SETTINGS['notification_sound']) if SETTINGS['notification_sound'] != 'off' else None

0 commit comments

Comments
 (0)