- change enum to typealias
This commit is contained in:
w-okada 2023-07-07 02:23:20 +09:00
parent d5561c2212
commit 89a06b65ec
2 changed files with 10 additions and 10 deletions

View File

@ -81,11 +81,10 @@ PitchExtractorType: TypeAlias = Literal[
"crepe_tiny", "crepe_tiny",
] ]
ServerAudioDeviceType: TypeAlias = Literal[
class ServerAudioDeviceTypes(Enum): "audioinput",
audioinput = "audioinput" "audiooutput"
audiooutput = "audiooutput" ]
RVCSampleMode: TypeAlias = Literal[ RVCSampleMode: TypeAlias = Literal[
"production", "production",

View File

@ -1,14 +1,15 @@
import sounddevice as sd import sounddevice as sd
from dataclasses import dataclass, field from dataclasses import dataclass, field
from const import ServerAudioDeviceTypes
import numpy as np import numpy as np
from const import ServerAudioDeviceType
# from const import SERVER_DEVICE_SAMPLE_RATES # from const import SERVER_DEVICE_SAMPLE_RATES
@dataclass @dataclass
class ServerAudioDevice: class ServerAudioDevice:
kind: ServerAudioDeviceTypes = ServerAudioDeviceTypes.audioinput kind: ServerAudioDeviceType = "audioinput"
index: int = 0 index: int = 0
name: str = "" name: str = ""
hostAPI: str = "" hostAPI: str = ""
@ -22,7 +23,7 @@ def dummy_callback(data: np.ndarray, frames, times, status):
pass pass
def checkSamplingRate(deviceId: int, desiredSamplingRate: int, type: ServerAudioDeviceTypes): def checkSamplingRate(deviceId: int, desiredSamplingRate: int, type: ServerAudioDeviceType):
if type == "input": if type == "input":
try: try:
with sd.InputStream( with sd.InputStream(
@ -71,7 +72,7 @@ def list_audio_device():
serverAudioOutputDevices: list[ServerAudioDevice] = [] serverAudioOutputDevices: list[ServerAudioDevice] = []
for d in inputAudioDeviceList: for d in inputAudioDeviceList:
serverInputAudioDevice: ServerAudioDevice = ServerAudioDevice( serverInputAudioDevice: ServerAudioDevice = ServerAudioDevice(
kind=ServerAudioDeviceTypes.audioinput, kind="audioinput",
index=d["index"], index=d["index"],
name=d["name"], name=d["name"],
hostAPI=hostapis[d["hostapi"]]["name"], hostAPI=hostapis[d["hostapi"]]["name"],
@ -82,7 +83,7 @@ def list_audio_device():
serverAudioInputDevices.append(serverInputAudioDevice) serverAudioInputDevices.append(serverInputAudioDevice)
for d in outputAudioDeviceList: for d in outputAudioDeviceList:
serverOutputAudioDevice: ServerAudioDevice = ServerAudioDevice( serverOutputAudioDevice: ServerAudioDevice = ServerAudioDevice(
kind=ServerAudioDeviceTypes.audiooutput, kind="audiooutput",
index=d["index"], index=d["index"],
name=d["name"], name=d["name"],
hostAPI=hostapis[d["hostapi"]]["name"], hostAPI=hostapis[d["hostapi"]]["name"],