### Install FlashAttention with uv Source: https://github.com/aratako/miocodec/blob/main/README.md Install FlashAttention using uv with --no-build-isolation. Ensure ninja is installed to avoid slow builds. ```bash uv pip install flash-attn --no-build-isolation ``` -------------------------------- ### Install MioCodec from Git with uv or pip Source: https://github.com/aratako/miocodec/blob/main/README.md Install the package directly from the Git repository using either uv or pip. Choose one command. ```bash uv add git+https://github.com/Aratako/MioCodec # or pip install git+https://github.com/Aratako/MioCodec ``` -------------------------------- ### Clone and install MioCodec in editable mode Source: https://github.com/aratako/miocodec/blob/main/README.md Clone the repository and install in editable mode using uv sync or pip install -e . ```bash git clone https://github.com/Aratako/MioCodec cd MioCodec ``` ```bash uv sync # or pip install -e . ``` -------------------------------- ### Voice conversion with MioCodec Source: https://github.com/aratako/miocodec/blob/main/README.md Combine content tokens from a source audio with the global embedding from a reference audio to perform voice conversion using the voice_conversion helper. ```python # Voice conversion (content from source, speaker from reference) source = load_audio("path/to/source.wav", sample_rate=model.config.sample_rate).cuda() reference = load_audio("path/to/reference.wav", sample_rate=model.config.sample_rate).cuda() # Perform voice conversion vc_wave = model.voice_conversion(source, reference) sf.write("vc.wav", vc_wave.cpu().numpy(), samplerate=model.config.sample_rate) ``` -------------------------------- ### Inference with legacy MioCodec-25Hz-44.1kHz Source: https://github.com/aratako/miocodec/blob/main/README.md Load the legacy model, encode audio, and decode using the external MioVocoder. Note the different decode signature and samplerate argument. ```python from miocodec import MioCodec, load_audio import soundfile as sf # Load model from Hugging Face model = MioCodec.from_pretrained("Aratako/MioCodec-25Hz-44.1kHz") model = model.eval().cuda() # Load audio waveform = load_audio("path/to/audio.wav", sample_rate=model.config.sample_rate).cuda() # Encode features = model.encode(waveform) # Decode to waveform resynth = model.decode(features=features) # Save sf.write("resynth.wav", resynth.cpu().numpy(), samplerate=model.config.sample_rate) ``` -------------------------------- ### Inference with MioCodec-25Hz-44.1kHz-v2 or 24kHz Source: https://github.com/aratako/miocodec/blob/main/README.md Load a recommended model, encode audio, and decode directly to waveform without an external vocoder. Use the 44.1kHz or 24kHz model by changing the model ID. ```python from miocodec import MioCodecModel, load_audio import soundfile as sf # Load model from Hugging Face # Use "Aratako/MioCodec-25Hz-44.1kHz-v2" for 44.1kHz or "Aratako/MioCodec-25Hz-24kHz" for 24kHz model = MioCodecModel.from_pretrained("Aratako/MioCodec-25Hz-44.1kHz-v2") model = model.eval().cuda() # Load audio waveform = load_audio("path/to/audio.wav", sample_rate=model.config.sample_rate).cuda() # Encode features = model.encode(waveform) # Decode to waveform (directly, no vocoder needed) resynth = model.decode( content_token_indices=features.content_token_indices, global_embedding=features.global_embedding, ) # Save sf.write("resynth.wav", resynth.cpu().numpy(), model.config.sample_rate) ```