From 89a06b65ec9f138d720a07da7f42efb53a2b45ef Mon Sep 17 00:00:00 2001 From: w-okada Date: Fri, 7 Jul 2023 02:23:20 +0900 Subject: [PATCH] Refctor - change enum to typealias --- server/const.py | 9 ++++----- server/voice_changer/Local/AudioDeviceList.py | 11 ++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/const.py b/server/const.py index 6a9b4e66..519794ab 100644 --- a/server/const.py +++ b/server/const.py @@ -81,11 +81,10 @@ PitchExtractorType: TypeAlias = Literal[ "crepe_tiny", ] - -class ServerAudioDeviceTypes(Enum): - audioinput = "audioinput" - audiooutput = "audiooutput" - +ServerAudioDeviceType: TypeAlias = Literal[ + "audioinput", + "audiooutput" +] RVCSampleMode: TypeAlias = Literal[ "production", diff --git a/server/voice_changer/Local/AudioDeviceList.py b/server/voice_changer/Local/AudioDeviceList.py index afb3d10d..fb731847 100644 --- a/server/voice_changer/Local/AudioDeviceList.py +++ b/server/voice_changer/Local/AudioDeviceList.py @@ -1,14 +1,15 @@ import sounddevice as sd from dataclasses import dataclass, field -from const import ServerAudioDeviceTypes import numpy as np + +from const import ServerAudioDeviceType # from const import SERVER_DEVICE_SAMPLE_RATES @dataclass class ServerAudioDevice: - kind: ServerAudioDeviceTypes = ServerAudioDeviceTypes.audioinput + kind: ServerAudioDeviceType = "audioinput" index: int = 0 name: str = "" hostAPI: str = "" @@ -22,7 +23,7 @@ def dummy_callback(data: np.ndarray, frames, times, status): pass -def checkSamplingRate(deviceId: int, desiredSamplingRate: int, type: ServerAudioDeviceTypes): +def checkSamplingRate(deviceId: int, desiredSamplingRate: int, type: ServerAudioDeviceType): if type == "input": try: with sd.InputStream( @@ -71,7 +72,7 @@ def list_audio_device(): serverAudioOutputDevices: list[ServerAudioDevice] = [] for d in inputAudioDeviceList: serverInputAudioDevice: ServerAudioDevice = ServerAudioDevice( - kind=ServerAudioDeviceTypes.audioinput, + kind="audioinput", index=d["index"], name=d["name"], hostAPI=hostapis[d["hostapi"]]["name"], @@ -82,7 +83,7 @@ def list_audio_device(): serverAudioInputDevices.append(serverInputAudioDevice) for d in outputAudioDeviceList: serverOutputAudioDevice: ServerAudioDevice = ServerAudioDevice( - kind=ServerAudioDeviceTypes.audiooutput, + kind="audiooutput", index=d["index"], name=d["name"], hostAPI=hostapis[d["hostapi"]]["name"],