Views
No views yet
Korean Speech (Mel Spectrogram) → Qwen3-Omni Audio Encoder → Audio Projection → Qwen3-4B LLM → Tool Callstools parameter)1from modeling_sori_speech import SoriSpeechForConditionalGeneration
2from processing_sori_speech import SoriSpeechProcessor
3from sori_speech_utils import process_mm_info
4import torch
5
6model = SoriSpeechForConditionalGeneration.from_pretrained(
7 "Seungyoun/Sori-4B-FC",
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10 trust_remote_code=True,
11)
12model.eval()
13processor = SoriSpeechProcessor.from_pretrained("Seungyoun/Sori-4B-FC")
14
15# Define tools (Qwen3 chat template format)
16tools = [
17 {
18 "type": "function",
19 "function": {
20 "name": "get_weather",
21 "description": "Get current weather for a city",
22 "parameters": {
23 "type": "object",
24 "properties": {
25 "city": {"type": "string", "description": "City name"}
26 },
27 "required": ["city"],
28 },
29 },
30 },
31]
32
33# Build conversation with audio input
34conversation = [
35 {
36 "role": "system",
37 "content": "You are a helpful voice assistant that can understand Korean speech and call tools when needed.",
38 },
39 {
40 "role": "user",
41 "content": [{"type": "audio", "audio": "weather.mp3"}],
42 },
43]
44
45# Process
46text = processor.apply_chat_template(
47 conversation, tools=tools, add_generation_prompt=True, tokenize=False,
48)
49audios, images, videos = process_mm_info(conversation, use_audio_in_video=False)
50inputs = processor(text=text, audio=audios, return_tensors="pt", padding=True)
51inputs = {
52 k: v.to(model.device).to(model.dtype)
53 if isinstance(v, torch.Tensor) and v.is_floating_point()
54 else v.to(model.device) if isinstance(v, torch.Tensor) else v
55 for k, v in inputs.items()
56}
57
58# Generate
59with torch.no_grad():
60 output_ids = model.generate(
61 **inputs,
62 max_new_tokens=512,
63 temperature=0.7,
64 do_sample=True,
65 pad_token_id=processor.tokenizer.pad_token_id,
66 eos_token_id=processor.tokenizer.eos_token_id,
67 )
68
69result = processor.decode(output_ids[0], skip_special_tokens=False)
70result = result.replace("<|im_end|>", "").replace("<|endoftext|>", "").strip()
71print(result)
72# <tool_call>
73# {"name": "get_weather", "arguments": {"city": "Seoul"}}
74# </tool_call>| Audio (Korean Speech) | Generated Tool Call |
|---|---|
| "혹시 지금 서울 날씨가 어떻게돼?" | get_weather({"city": "Seoul"}) |