(feat) Make audio playback cross platform

This commit is contained in:
dfgHiatus committed 2025-02-19 08:38:22 -06:00
1 parent 1f22c5363e
commit ddca4bf659
7 files changed
+23 -36

No files matched your search

+2 -2
View File
@@ -11,7 +11,7 @@ import numpy as np
import cv2
from enum import Enum
from one_euro_filter import OneEuroFilter
from utils.misc_utils import playSound, SND_FILENAME, SND_ASYNC, onnx_providers
from utils.misc_utils import playSound, onnx_providers
import importlib
from osc import Tab
from osc_calibrate_filter import *
@@ -37,7 +37,7 @@ def run_once(f):
async def delayed_setting_change(setting, value):
await asyncio.sleep(5)
setting = value
playSound("Audio/completed.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "completed.wav"))
class BabbleProcessor:
+2 -4
View File
@@ -3,14 +3,13 @@ from queue import Queue, Empty
from threading import Event, Thread
import FreeSimpleGUI as sg
import cv2
import os
from babble_processor import BabbleProcessor, CamInfoOrigin
from camera import Camera, CameraState, MAX_RESOLUTION
from config import BabbleConfig
from osc import Tab
from utils.misc_utils import (
playSound,
SND_FILENAME,
SND_ASYNC,
list_camera_names,
get_camera_index_by_name,
bg_color_highlight,
@@ -19,7 +18,6 @@ from utils.misc_utils import (
)
from lang_manager import LocaleStringManager as lang
class CameraWidget:
def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
self.gui_camera_addr = f"-CAMERAADDR{widget_id}-"
@@ -441,7 +439,7 @@ class CameraWidget:
values[self.use_calibration] == True
): # Don't start recording if the calibration filter is disabled.
self.babble_cnn.calibration_frame_counter = 1500
playSound("Audio/start.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "start.wav"))
if event == self.gui_stop_calibration:
if (
+2 -5
View File
@@ -11,7 +11,7 @@ import numpy as np
import cv2
from enum import Enum
from one_euro_filter import OneEuroFilter
from utils.misc_utils import playSound, SND_FILENAME, SND_ASYNC, onnx_providers
from utils.misc_utils import playSound, onnx_providers
from osc_calibrate_filter import *
from tab import CamInfo, CamInfoOrigin
from landmark_model_loader import *
@@ -28,13 +28,10 @@ def run_once(f):
wrapper.has_run = False
return wrapper
async def delayed_setting_change(setting, value):
await asyncio.sleep(5)
setting = value
playSound('Audio/completed.wav', SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "completed.wav"))
class LandmarkProcessor:
def __init__(
+3 -5
View File
@@ -1,5 +1,5 @@
from pythonosc import udp_client, osc_server, dispatcher
from utils.misc_utils import playSound, SND_FILENAME, SND_ASYNC
from utils.misc_utils import playSound
import queue
import threading
from enum import IntEnum
@@ -7,19 +7,17 @@ import time
from config import BabbleConfig
import traceback
import math
import os
from lang_manager import LocaleStringManager as lang
class Tab(IntEnum):
CAM = 0
SETTINGS = 1
ALGOSETTINGS = 2
CALIBRATION = 3
import numpy as np
def delay_output_osc(array, delay_seconds, self):
time.sleep(delay_seconds)
output_osc(array, self)
@@ -152,7 +150,7 @@ class VRChatOSCReceiver:
if osc_value:
for cam in self.cams:
cam.babble_cnn.calibration_frame_counter = 300
playSound("Audio/start.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "start.wav"))
def run(self):
+3 -5
View File
@@ -1,17 +1,15 @@
import numpy as np
from math import log
from enum import IntEnum
from utils.misc_utils import playSound, SND_FILENAME, SND_ASYNC
from utils.misc_utils import playSound
import os
from lang_manager import LocaleStringManager as lang
class CamId(IntEnum):
CAM = 0
SETTINGS = 1
class cal:
def __init__(self):
self.calibration_frame_counter = None
self.calibrated_array = None
@@ -57,7 +55,7 @@ class cal:
f'[{lang._instance.get_string("log.info")}] Calibration completed.'
)
playSound("Audio/completed.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "completed.wav"))
if self.settings.calibration_mode == "Neutral":
self.min_max_array = np.fromstring(
+3 -1
View File
@@ -15,4 +15,6 @@ comtypes==1.4.8;
pygrabber==0.2;
psutil==7.0.0;
requests==2.32.3;
v4l2py==3.0.0;
v4l2py==3.0.0;
sounddevice=0.5.1;
soundfile-0.13.1;
+8 -14
View File
@@ -7,6 +7,8 @@ import platform
import cv2
import re
import subprocess
import sounddevice as sd
import soundfile as sf
bg_color_highlight = "#424042"
bg_color_clear = "#242224"
@@ -169,23 +171,15 @@ def get_camera_index_by_name(name):
return None
# Placeholder for sound functions on Windows
def playSound(*args, **kwargs):
pass
# Set environment variable before importing sounddevice. Value is not important.
os.environ["SD_ENABLE_ASIO"] = "1"
def playSound(file):
data, fs = sf.read(file)
sd.play(data, fs)
sd.wait()
# Handle debugging virtual envs.
def ensurePath():
if os.path.exists(os.path.join(os.getcwd(), "BabbleApp")):
os.chdir(os.path.join(os.getcwd(), "BabbleApp"))
SND_FILENAME = SND_ASYNC = 1
if os_type == 'Windows':
import winsound
playSound = winsound.PlaySound
SND_FILENAME = winsound.SND_FILENAME
SND_ASYNC = winsound.SND_ASYNC