2025-02-23 14:38:21 +08:00
|
|
|
import importlib
|
|
|
|
|
import logging
|
2025-02-02 23:01:14 +08:00
|
|
|
import os
|
2025-02-18 20:30:03 +08:00
|
|
|
import sys
|
2025-02-23 14:38:21 +08:00
|
|
|
import time
|
|
|
|
|
import wave
|
2025-02-02 23:01:14 +08:00
|
|
|
import uuid
|
2025-02-23 14:38:21 +08:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
from typing import Optional, Tuple, List
|
|
|
|
|
from core.providers.asr.base import ASRProviderBase
|
|
|
|
|
from config.logger import setup_logging
|
2025-02-02 23:01:14 +08:00
|
|
|
|
2025-02-18 00:07:19 +08:00
|
|
|
TAG = __name__
|
|
|
|
|
logger = setup_logging()
|
2025-02-02 23:01:14 +08:00
|
|
|
|
2025-02-23 14:38:21 +08:00
|
|
|
def create_instance(class_name: str, *args, **kwargs) -> ASRProviderBase:
|
2025-02-02 23:01:14 +08:00
|
|
|
"""工厂方法创建ASR实例"""
|
2025-02-23 14:38:21 +08:00
|
|
|
if os.path.exists(os.path.join('core', 'providers', 'asr', f'{class_name}.py')):
|
|
|
|
|
lib_name = f'core.providers.asr.{class_name}'
|
|
|
|
|
if lib_name not in sys.modules:
|
|
|
|
|
sys.modules[lib_name] = importlib.import_module(f'{lib_name}')
|
|
|
|
|
return sys.modules[lib_name].ASRProvider(*args, **kwargs)
|
2025-02-02 23:01:14 +08:00
|
|
|
|
2025-02-23 14:38:21 +08:00
|
|
|
raise ValueError(f"不支持的ASR类型: {class_name},请检查该配置的type是否设置正确")
|