mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-21 22:53:56 +08:00
37 lines
868 B
Python
37 lines
868 B
Python
import logging
|
|
from typing import Any
|
|
|
|
from ..core import MicrophoneListener
|
|
from .base import Plugin
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class AudioPlugin(Plugin):
|
|
name = "audio"
|
|
priority = 10
|
|
|
|
def __init__(self) -> None:
|
|
self.app = None
|
|
self.source: MicrophoneListener | None = None
|
|
|
|
def setup(self, app: Any) -> None:
|
|
self.app = app
|
|
self.source = MicrophoneListener(app.config)
|
|
self.app.audio_source = self.source
|
|
|
|
def start(self) -> None:
|
|
if self.source is None:
|
|
logger.warning("audio source not initialized")
|
|
return
|
|
self.source.start()
|
|
|
|
def stop(self) -> None:
|
|
if self.source is not None:
|
|
self.source.stop()
|
|
|
|
def shutdown(self) -> None:
|
|
self.stop()
|
|
if self.app is not None:
|
|
self.app.audio_source = None
|