fujielab-moshi-client
Fujie lab. version of Moshi client library for Python programs.
Overview
A Moshi client library for voice assistants and chatbots. Enables sending and receiving audio and text data via WebSocket.
Installation
pip install fujielab-moshi-client
Or clone the repository and install dependencies with requirements.txt:
pip install -r requirements.txt
Usage
MoshiClient Class Example
from fujielab.moshi.moshi_client_lib import MoshiClient
import numpy as np
# Initialize MoshiClient
client = MoshiClient()
# Connect to server (blocking)
client.connect("ws://localhost:8998/api/chat")
# Send audio data (PCM float32, 1D np.array)
audio_data = np.array([...], dtype=np.float32)
client.add_audio_input(audio_data)
# Get audio data from server
received_audio = client.get_audio_output()
# Get text response from server
text_response = client.get_text_output()
# Disconnect
client.disconnect()
MoshiClient Parameters
- text_temperature: Temperature parameter for text generation (default: 0.7)
- text_topk: Top-K sampling for text generation (default: 25)
- audio_temperature: Temperature parameter for audio generation (default: 0.8)
- audio_topk: Top-K sampling for audio generation (default: 250)
- pad_mult: Audio padding multiplier (default: 0.0) not effective
- repetition_penalty: Repetition penalty (default: 1.0) not effective
- repetition_penalty_context: Context length for repetition penalty (default: 64) not effective
- output_buffer_size: Size of audio output buffer (default: 1920 samples)
About Audio Frame Size
Audio Input (add_audio_input):
- You can send audio data of any size
- Internally buffered automatically to the appropriate size (1920 samples) and sent to the Moshi server
- Example: 160 samples, 480 samples, 2000 samples, etc. - any size is supported
Audio Output (get_audio_output):
- The size of output audio data must be specified in the
MoshiClientconstructor - Specified with the
output_buffer_sizeparameter (default: 1920 samples) - Example:
# To get 480 samples (20ms @ 24kHz) at a time
client = MoshiClient(output_buffer_size=480)
# To get 960 samples (40ms @ 24kHz) at a time
client = MoshiClient(output_buffer_size=960)
Important Notes: The Moshi server generates audio in 80ms (1920 samples) units. Therefore, please note the following points in operation:
- When providing data less than 1920 samples with
add_audio_input, it will not be sent to the Moshi server immediately. Data accumulates in the internal buffer and is sent together when it reaches 1920 samples. - If you call
get_audio_outputbefore data is sent to the Moshi server, no audio data will be returned.
Running Simple Client
python -m fujielab.moshi.simple_moshi_client
For detailed usage, please refer to the help:
python -m fujielab.moshi.simple_moshi_client --help
Dependencies
- websockets
- sounddevice
- numpy
- opuslib
- soxr
License
Apache License 2.0 See LICENSE for details.
Metadata
Release files for fujielab-moshi-client 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fujielab_moshi_client-0.1.2.tar.gz | 24.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fujielab_moshi_client-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.1 kB
Release files / fujielab_moshi_client-0.1.2.tar.gz
| Download URL | fujielab_moshi_client-0.1.2.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0fbe6872a66eb5ef260d503b6e3226bafb6f6e131494edc7ea63f38d5d8f496
|
|
BLAKE2b-256 checksum How to use checksums |
b8b8134e3528561fd3986ff9b101b5d143dafeb09bc8c0540b433d3f6e647362
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|
Release files / fujielab_moshi_client-0.1.2-py3-none-any.whl
| Download URL | fujielab_moshi_client-0.1.2-py3-none-any.whl |
|---|---|
| Size | 23.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d1a4053b9e3222ac1908ed870aa01ca9959f4161f6abe6e1c6a058d2ddeee51
|
|
BLAKE2b-256 checksum How to use checksums |
6f97bf96460ec91083a02792bb50e128b8521fb3c3408fd111d956a39661ae5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|