mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
26 lines
878 B
Python
26 lines
878 B
Python
import importlib
|
|
import logging
|
|
import os
|
|
import sys
|
|
import time
|
|
import wave
|
|
import uuid
|
|
from abc import ABC, abstractmethod
|
|
from typing import Optional, Tuple, List
|
|
from core.providers.asr.base import ASRProviderBase
|
|
from config.logger import setup_logging
|
|
|
|
TAG = __name__
|
|
logger = setup_logging()
|
|
|
|
|
|
def create_instance(class_name: str, *args, **kwargs) -> ASRProviderBase:
|
|
"""Factory method to create ASR instance"""
|
|
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)
|
|
|
|
raise ValueError(
|
|
f"Unsupported ASR type: {class_name}, please check if the type in this configuration is set correctly")
|