|
| 1 | +## Use Cases |
| 2 | + |
| 3 | +> This task takes `audio` and a `text prompt` and returns `text` (answers, summaries, structured notes, etc.). |
| 4 | +
|
| 5 | +### Audio question answering |
| 6 | + |
| 7 | +Ask targeted questions about lectures, podcasts, or calls and get context-aware answers. |
| 8 | +**Example:** Audio: physics lecture → Prompt: “What did the teacher say about gravity and how is it measured?” |
| 9 | + |
| 10 | +### Meeting notes & action items |
| 11 | + |
| 12 | +Turn multi-speaker meetings into concise minutes with decisions, owners, and deadlines. |
| 13 | +**Example:** Audio: weekly stand-up → Prompt: “Summarize key decisions and list action items with assignees.” |
| 14 | + |
| 15 | +### Speech understanding & intent |
| 16 | + |
| 17 | +Go beyond transcription to extract intent, sentiment, uncertainty, or emotion from spoken language. |
| 18 | +**Example:** “I’m not sure I can finish this on time.” → Prompt: “Describe speaker intent and confidence.” |
| 19 | + |
| 20 | +### Music & sound analysis (textual) |
| 21 | + |
| 22 | +Describe instrumentation, genre, tempo, or sections, and suggest edits or techniques (text output only). |
| 23 | +**Example:** Song demo → Prompt: “Identify key and tempo, then suggest jazz reharmonization ideas for the chorus.” |
| 24 | + |
| 25 | +## Inference |
| 26 | + |
| 27 | +You can use the 'transformers' library, and your audio file to any of the `audio-text-to-text` model, with instructions and get text responses. Following code examples show how to do so. |
| 28 | + |
| 29 | +### Speech Transcription and Analysis |
| 30 | + |
| 31 | +These models don’t just turn speech into text—they also capture tone, emotion, and speaker traits. This makes them useful for tasks like sentiment analysis or identifying speaker profiles. |
| 32 | + |
| 33 | +You can try audio transcription with [Voxtral Mini](https://huggingface.co/mistralai/Voxtral-Mini-3B-2507) using the following code. |
| 34 | + |
| 35 | +```python |
| 36 | +from transformers import VoxtralForConditionalGeneration, AutoProcessor |
| 37 | +import torch |
| 38 | + |
| 39 | +device = "cuda" |
| 40 | +repo_id = "mistralai/Voxtral-Mini-3B-2507" |
| 41 | + |
| 42 | +processor = AutoProcessor.from_pretrained(repo_id) |
| 43 | +model = VoxtralForConditionalGeneration.from_pretrained(repo_id, dtype=torch.bfloat16, device_map=device) |
| 44 | + |
| 45 | +inputs = processor.apply_transcription_request(language="en", audio="https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3", model_id=repo_id) |
| 46 | +inputs = inputs.to(device, dtype=torch.bfloat16) |
| 47 | + |
| 48 | +outputs = model.generate(**inputs, max_new_tokens=500) |
| 49 | +decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True) |
| 50 | + |
| 51 | +print("\nGenerated responses:") |
| 52 | +print("=" * 80) |
| 53 | +for decoded_output in decoded_outputs: |
| 54 | + print(decoded_output) |
| 55 | + print("=" * 80) |
| 56 | +``` |
| 57 | + |
| 58 | +### Audio Question Answering |
| 59 | + |
| 60 | +These models can understand audio directly and answer questions about it. For example, summarizing a podcast clip or explaining parts of a recorded conversation. |
| 61 | + |
| 62 | +You can experiment with [Qwen2-Audio-Instruct-Demo](https://huggingface.co/Qwen/Qwen2-Audio-Instruct-Demo) for conversations with both text and audio inputs, letting you ask follow-up questions about different sounds or speech clips. |
| 63 | + |
| 64 | +```python |
| 65 | +from io import BytesIO |
| 66 | +from urllib.request import urlopen |
| 67 | +import librosa |
| 68 | +from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor |
| 69 | + |
| 70 | +processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct") |
| 71 | +model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto") |
| 72 | + |
| 73 | +conversation = [ |
| 74 | + {'role': 'system', 'content': 'You are a helpful assistant.'}, |
| 75 | + {"role": "user", "content": [ |
| 76 | + {"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/glass-breaking-151256.mp3"}, |
| 77 | + {"type": "text", "text": "What's that sound?"}, |
| 78 | + ]}, |
| 79 | + {"role": "assistant", "content": "It is the sound of glass shattering."}, |
| 80 | + {"role": "user", "content": [ |
| 81 | + {"type": "text", "text": "What can you do when you hear that?"}, |
| 82 | + ]}, |
| 83 | + {"role": "assistant", "content": "Stay alert and cautious, and check if anyone is hurt or if there is any damage to property."}, |
| 84 | + {"role": "user", "content": [ |
| 85 | + {"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/1272-128104-0000.flac"}, |
| 86 | + {"type": "text", "text": "What does the person say?"}, |
| 87 | + ]}, |
| 88 | +] |
| 89 | +text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False) |
| 90 | +audios = [] |
| 91 | +for message in conversation: |
| 92 | + if isinstance(message["content"], list): |
| 93 | + for ele in message["content"]: |
| 94 | + if ele["type"] == "audio": |
| 95 | + audios.append( |
| 96 | + librosa.load( |
| 97 | + BytesIO(urlopen(ele['audio_url']).read()), |
| 98 | + sr=processor.feature_extractor.sampling_rate)[0] |
| 99 | + ) |
| 100 | + |
| 101 | +inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True) |
| 102 | +inputs.input_ids = inputs.input_ids.to("cuda") |
| 103 | + |
| 104 | +generate_ids = model.generate(**inputs, max_length=256) |
| 105 | +generate_ids = generate_ids[:, inputs.input_ids.size(1):] |
| 106 | + |
| 107 | +response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0] |
| 108 | +``` |
| 109 | + |
| 110 | +## Useful Resources |
| 111 | + |
| 112 | +If you want to learn more about this concept, here are some useful links: |
| 113 | + |
| 114 | +### Papers |
| 115 | + |
| 116 | +- [SpeechGPT](https://huggingface.co/papers/2507.13264) — multimodal dialogue with speech and text. |
| 117 | +- [Voxtral](https://huggingface.co/papers/2507.13264) — a state-of-the-art audio-text model. |
| 118 | +- [Qwen2-audio-instruct](https://huggingface.co/papers/2407.10759) — large-scale audio-language modeling for instruction following. |
| 119 | +- [AudioPaLM](https://huggingface.co/papers/2306.12925) — scaling audio-language models with PaLM. |
| 120 | + |
| 121 | +### Models, Codes & Demos |
| 122 | + |
| 123 | +- [Qwen2-audio-instruct](https://github.com/QwenLM/Qwen2-Audio) — open-source implementation with demos. |
| 124 | +- [SpeechGPT](https://github.com/0nutation/SpeechGPT) — An end-to-end framework for audio conversational models built on top of large language models. |
| 125 | +- [AudioPaLM](https://google-research.github.io/seanet/audiopalm/examples/) — resources and code for AudioPaLM. |
| 126 | +- [Audio Flamingo](https://huggingface.co/nvidia/audio-flamingo-3) — unifies speech, sound, and music understanding with long-context reasoning. |
| 127 | +- [Ultravox](https://github.com/fixie-ai/ultravox) — a fast multimodal large language model designed for real-time voice interactions. |
| 128 | +- [Ichigo](https://github.com/menloresearch/ichigo) — an audio-text-to-text model for audio-related tasks. |
| 129 | + |
| 130 | +### Datasets |
| 131 | + |
| 132 | +- [nvidia/AF-Think](https://huggingface.co/datasets/nvidia/AF-Think) |
| 133 | +- [nvidia/AudioSkills](https://huggingface.co/datasets/nvidia/AudioSkills) |
| 134 | + |
| 135 | +### Tools & Extras |
| 136 | + |
| 137 | +- [Fast-RTC](https://huggingface.co/fastrtc) — turn any Python function into a real-time audio/video stream. |
| 138 | +- [PhiCookBook](https://github.com/microsoft/PhiCookBook) — Microsoft’s open-source guide to small language models. |
| 139 | +- [Qwen2-audio-instruct](https://qwenlm.github.io/blog/qwen2-audio/) — Blogpost explaining usage and demos of Qwen2-audio-instruct. |
0 commit comments