Skip to main content

Fujie lab. version of Moshi client library for Python programs.

Project description

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 MoshiClient constructor
  • Specified with the output_buffer_size parameter (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_output before 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fujielab_moshi_client-0.1.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fujielab_moshi_client-0.1.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file fujielab_moshi_client-0.1.0.tar.gz.

File metadata

  • Download URL: fujielab_moshi_client-0.1.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for fujielab_moshi_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 350cc98e652e49751cdd8bd4765c78ef1c36f302f3dc3f28a74a4310385c3012
MD5 24a267b3193ac2e5acecf8c280076497
BLAKE2b-256 675ef8a29a5d6a4f76ce13ec37904c5678ea4d93048d625baaea3d4351335640

See more details on using hashes here.

File details

Details for the file fujielab_moshi_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fujielab_moshi_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d6330f0081068f5cfe4e8f5d349cc06c72a7e987549bd63f80afa3c6713e73c
MD5 82d0ac98b472a59eda4baa2193423d6a
BLAKE2b-256 6ae72feb2d71479eae6b4742d9800e9fa82b1025cea00e11fbf72c255762dee4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page