mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 01:49:23 +08:00
[feat] update some feature
sync code of fastrtc, add text support through datachannel, fix safari connect problem support chat without camera or mic
This commit is contained in:
@@ -51,4 +51,73 @@ Example
|
||||
>>> audio_tuple = (sample_rate, audio_data)
|
||||
>>> file_path = audio_to_file(audio_tuple)
|
||||
>>> print(f"Audio saved to: {file_path}")
|
||||
```
|
||||
|
||||
## `aggregate_bytes_to_16bit`
|
||||
Aggregate bytes to 16-bit audio samples.
|
||||
|
||||
This function takes an iterator of chunks and aggregates them into 16-bit audio samples.
|
||||
It handles incomplete samples and combines them with the next chunk.
|
||||
|
||||
Parameters
|
||||
```
|
||||
chunks_iterator : Iterator[bytes]
|
||||
An iterator of byte chunks to aggregate
|
||||
```
|
||||
Returns
|
||||
```
|
||||
Iterator[NDArray[np.int16]]
|
||||
An iterator of 16-bit audio samples
|
||||
```
|
||||
Example
|
||||
```python
|
||||
>>> chunks_iterator = [b'\x00\x01', b'\x02\x03', b'\x04\x05']
|
||||
>>> for chunk in aggregate_bytes_to_16bit(chunks_iterator):
|
||||
>>> print(chunk)
|
||||
```
|
||||
|
||||
## `async_aggregate_bytes_to_16bit`
|
||||
|
||||
Aggregate bytes to 16-bit audio samples asynchronously.
|
||||
|
||||
Parameters
|
||||
```
|
||||
chunks_iterator : Iterator[bytes]
|
||||
An iterator of byte chunks to aggregate
|
||||
```
|
||||
Returns
|
||||
```
|
||||
Iterator[NDArray[np.int16]]
|
||||
An iterator of 16-bit audio samples
|
||||
```
|
||||
Example
|
||||
```python
|
||||
>>> chunks_iterator = [b'\x00\x01', b'\x02\x03', b'\x04\x05']
|
||||
>>> for chunk in async_aggregate_bytes_to_16bit(chunks_iterator):
|
||||
>>> print(chunk)
|
||||
```
|
||||
|
||||
## `wait_for_item`
|
||||
|
||||
Wait for an item from an asyncio.Queue with a timeout.
|
||||
|
||||
Parameters
|
||||
```
|
||||
queue : asyncio.Queue
|
||||
The queue to wait for an item from
|
||||
timeout : float
|
||||
The timeout in seconds
|
||||
```
|
||||
Returns
|
||||
```
|
||||
Any
|
||||
The item from the queue or None if the timeout is reached
|
||||
```
|
||||
|
||||
Example
|
||||
```python
|
||||
>>> queue = asyncio.Queue()
|
||||
>>> queue.put_nowait(1)
|
||||
>>> item = await wait_for_item(queue)
|
||||
>>> print(item)
|
||||
```
|
||||
Reference in New Issue
Block a user