ear_agent.cpython-312.pyc•5.63 kB
�
n��g� � �f � d Z ddlZddlmZmZ ddlZddlmZ ddl m
Z
ddlmZm
Z
G d� de
� Zy) u
听觉智能体
� N)�Dict�Any)�SPEECH_RECOGNITION)� BaseAgent)�AudioMessage�TextMessagec �F � � e Zd Zdededef� fd�Z� fd�Z� fd�Zd� Z� xZ S )�EarAgent�agent_id�host�portc �j �� t �| � |d||� t j � | _ d| _ y )N�audio_inputF)�super�__init__�sr�
Recognizer�
recognizer�is_listening)�selfr r r
� __class__s ��,D:\AIProject\mcpTest\src\agents\ear_agent.pyr zEarAgent.__init__ s+ �� �
����=�$��=��-�-�/���!��� c � � �K � t �| � � � d{ ��� d| _ t j | j � � y7 �/�w)u 启动听觉智能体NT)r �startr �asyncio�create_task�_listen_loop�r r s �r r zEarAgent.start s: �� �� ��g�m�o��� ������D�-�-�/�0� �s �A�A�0Ac � �L �K � d| _ t �| � � � d{ ��� y7 ��w)u 停止听觉智能体FN)r r �stopr s �r r! z
EarAgent.stop s �� �� �!����g�l�n���s �$�"�$c
� �� K � | j r� d}t |� D ]� } t j � 5 }| j j |d�� | j j d� t j | j j |t d t d �� � d{ ��� } ddd� n | j r��yy7 �# 1 sw Y nxY wnd# t $ rX}| j j d |d
z � d|� d|� �� ||d
z
k( r� t j d
� � d{ ���7 Y d}~nd}~ww xY wt d
}t |� D ]� } t j | j j t d �� � d{ ���7 } nH# t j $ r1 ||d
z
k( r� t j t d � � d{ ���7 Y ��w xY w t# | j$ d�� } | j'