Views
No views yet

docker build command.1git clone https://github.com/MoonshotAI/Kimi-Audio
2git submodule update --init
3cd Kimi-Audio
4docker build -t kimi-audio:v0.1 .docker pull moonshotai/kimi-audio:v0.1pip install -r requirements.txtKimi-Audio-7B-Instruct model.1import soundfile as sf
2# Assuming the KimiAudio class is available after installation
3from kimia_infer.api.kimia import KimiAudio
4import torch # Ensure torch is imported if needed for device placement
5
6# --- 1. Load Model ---
7# Load the model from Hugging Face Hub
8# Make sure you are logged in (`huggingface-cli login`) if the repo is private.
9model_id = "moonshotai/Kimi-Audio-7B-Instruct" # Or "Kimi/Kimi-Audio-7B"
10device = "cuda" if torch.cuda.is_available() else "cpu" # Example device placement
11# Note: The KimiAudio class might handle model loading differently.
12# You might need to pass the model_id directly or download checkpoints manually
13# and provide the local path as shown in the original readme_kimia.md.
14# Please refer to the main Kimi-Audio repository for precise loading instructions.
15# Example assuming KimiAudio takes the HF ID or a local path:
16try:
17 model = KimiAudio(model_path=model_id, load_detokenizer=True) # May need device argument
18 model.to(device) # Example device placement
19except Exception as e:
20 print(f"Automatic loading from HF Hub might require specific setup.")
21 print(f"Refer to Kimi-Audio docs. Trying local path example (update path!). Error: {e}")
22 # Fallback example:
23 # model_path = "/path/to/your/downloaded/kimia-hf-ckpt" # IMPORTANT: Update this path if loading locally
24 # model = KimiAudio(model_path=model_path, load_detokenizer=True)
25 # model.to(device) # Example device placement
26
27# --- 2. Define Sampling Parameters ---
28sampling_params = {
29 "audio_temperature": 0.8,
30 "audio_top_k": 10,
31 "text_temperature": 0.0,
32 "text_top_k": 5,
33 "audio_repetition_penalty": 1.0,
34 "audio_repetition_window_size": 64,
35 "text_repetition_penalty": 1.0,
36 "text_repetition_window_size": 16,
37}
38
39# --- 3. Example 1: Audio-to-Text (ASR) ---
40# TODO: Provide actual example audio files or URLs accessible to users
41# E.g., download sample files first or use URLs
42# wget https://path/to/your/asr_example.wav -O asr_example.wav
43# wget https://path/to/your/qa_example.wav -O qa_example.wav
44asr_audio_path = "asr_example.wav" # IMPORTANT: Make sure this file exists
45qa_audio_path = "qa_example.wav" # IMPORTANT: Make sure this file exists
46
47messages_asr = [
48 {"role": "user", "message_type": "text", "content": "Please transcribe the following audio:"},
49 {"role": "user", "message_type": "audio", "content": asr_audio_path}
50]
51
52# Generate only text output
53# Note: Ensure the model object and generate method accept device placement if needed
54_, text_output = model.generate(messages_asr, **sampling_params, output_type="text")
55print(">>> ASR Output Text: ", text_output)
56# Expected output: "这并不是告别,这是一个篇章的结束,也是新篇章的开始。" (Example)
57
58# --- 4. Example 2: Audio-to-Audio/Text Conversation ---
59messages_conversation = [
60 {"role": "user", "message_type": "audio", "content": qa_audio_path}
61]
62
63# Generate both audio and text output
64wav_output, text_output = model.generate(messages_conversation, **sampling_params, output_type="both")
65
66# Save the generated audio
67output_audio_path = "output_audio.wav"
68# Ensure wav_output is on CPU and flattened before saving
69sf.write(output_audio_path, wav_output.detach().cpu().view(-1).numpy(), 24000) # Assuming 24kHz output
70print(f">>> Conversational Output Audio saved to: {output_audio_path}")
71print(">>> Conversational Output Text: ", text_output)
72# Expected output: "A." (Example)
73
74print("Kimi-Audio inference examples complete.")
751@misc{kimi_audio_2024,
2 title={Kimi-Audio Technical Report},
3 author={Kimi Team},
4 year={2024},
5 eprint={arXiv:placeholder},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}