Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Input

AudioInputdataclass

Static audio to be used as input for the VoicePipeline.

Source code insrc/agents/voice/input.py
@dataclassclassAudioInput:"""Static audio to be used as input for the VoicePipeline."""buffer:npt.NDArray[np.int16|np.float32]"""    A buffer containing the audio data for the agent. Must be a numpy array of int16 or float32.    """frame_rate:int=DEFAULT_SAMPLE_RATE"""The sample rate of the audio data. Defaults to 24000."""sample_width:int=2"""The sample width of the audio data. Defaults to 2."""channels:int=1"""The number of channels in the audio data. Defaults to 1."""defto_audio_file(self)->tuple[str,io.BytesIO,str]:"""Returns a tuple of (filename, bytes, content_type)"""return_buffer_to_audio_file(self.buffer,self.frame_rate,self.sample_width,self.channels)defto_base64(self)->str:"""Returns the audio data as a base64 encoded string."""ifself.buffer.dtype==np.float32:# convert to int16self.buffer=np.clip(self.buffer,-1.0,1.0)self.buffer=(self.buffer*32767).astype(np.int16)elifself.buffer.dtype!=np.int16:raiseUserError("Buffer must be a numpy array of int16 or float32")returnbase64.b64encode(self.buffer.tobytes()).decode("utf-8")

bufferinstance-attribute

buffer:NDArray[int16|float32]

A buffer containing the audio data for the agent. Must be a numpy array of int16 or float32.

frame_rateclass-attributeinstance-attribute

frame_rate:int=DEFAULT_SAMPLE_RATE

The sample rate of the audio data. Defaults to 24000.

sample_widthclass-attributeinstance-attribute

sample_width:int=2

The sample width of the audio data. Defaults to 2.

channelsclass-attributeinstance-attribute

channels:int=1

The number of channels in the audio data. Defaults to 1.

to_audio_file

to_audio_file()->tuple[str,BytesIO,str]

Returns a tuple of (filename, bytes, content_type)

Source code insrc/agents/voice/input.py
defto_audio_file(self)->tuple[str,io.BytesIO,str]:"""Returns a tuple of (filename, bytes, content_type)"""return_buffer_to_audio_file(self.buffer,self.frame_rate,self.sample_width,self.channels)

to_base64

to_base64()->str

Returns the audio data as a base64 encoded string.

Source code insrc/agents/voice/input.py
defto_base64(self)->str:"""Returns the audio data as a base64 encoded string."""ifself.buffer.dtype==np.float32:# convert to int16self.buffer=np.clip(self.buffer,-1.0,1.0)self.buffer=(self.buffer*32767).astype(np.int16)elifself.buffer.dtype!=np.int16:raiseUserError("Buffer must be a numpy array of int16 or float32")returnbase64.b64encode(self.buffer.tobytes()).decode("utf-8")

StreamedAudioInput

Audio input represented as a stream of audio data. You can pass this to theVoicePipelineand then push audio data into the queue using theadd_audio method.

Source code insrc/agents/voice/input.py
classStreamedAudioInput:"""Audio input represented as a stream of audio data. You can pass this to the `VoicePipeline`    and then push audio data into the queue using the `add_audio` method.    """def__init__(self):self.queue:asyncio.Queue[npt.NDArray[np.int16|np.float32]|None]=asyncio.Queue()asyncdefadd_audio(self,audio:npt.NDArray[np.int16|np.float32]|None):"""Adds more audio data to the stream.        Args:            audio: The audio data to add. Must be a numpy array of int16 or float32 or None.              If None passed, it indicates the end of the stream.        """awaitself.queue.put(audio)

add_audioasync

add_audio(audio:NDArray[int16|float32]|None)

Adds more audio data to the stream.

Parameters:

NameTypeDescriptionDefault
audioNDArray[int16 |float32] | None

The audio data to add. Must be a numpy array of int16 or float32 or None.If None passed, it indicates the end of the stream.

required
Source code insrc/agents/voice/input.py
asyncdefadd_audio(self,audio:npt.NDArray[np.int16|np.float32]|None):"""Adds more audio data to the stream.    Args:        audio: The audio data to add. Must be a numpy array of int16 or float32 or None.          If None passed, it indicates the end of the stream.    """awaitself.queue.put(audio)

[8]ページ先頭

©2009-2025 Movatter.jp