File size: 3,759 Bytes
a7c2243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.. _ten-minutes:

NeMo Speech Inference in 5 Minutes
===================================

This guide gives you a quick, hands-on tour of NeMo's core speech capabilities. By the end, you'll have transcribed audio, synthesized speech, identified speakers, and used a speech language model — all in about 50 lines of code.

.. note::

   Make sure you have :doc:`installed NeMo <install>` before starting.


1. Transcribe Speech (ASR)
--------------------------

Automatic Speech Recognition converts audio to text. NeMo's Parakeet model sits at the top of the `HuggingFace OpenASR Leaderboard <https://huggingface.co/spaces/hf-audio/open_asr_leaderboard>`_.

**Basic transcription** — 3 lines of code:

.. code-block:: python

   import nemo.collections.asr as nemo_asr

   asr_model = nemo_asr.models.ASRModel.from_pretrained("nvidia/parakeet-tdt-0.6b-v2")
   transcript = asr_model.transcribe(["audio.wav"])[0].text
   print(transcript)

**With timestamps** — know *when* each word was spoken:

.. code-block:: python

   hypotheses = asr_model.transcribe(["audio.wav"], timestamps=True)
   for stamp in hypotheses[0].timestamp['word']:
       print(f"{stamp['start']}s - {stamp['end']}s : {stamp['word']}")

**From the command line**:

.. code-block:: bash

   python examples/asr/transcribe_speech.py \
       pretrained_name="nvidia/parakeet-tdt-0.6b-v2" \
       audio_dir=./my_audio_files/


2. Synthesize Speech (TTS)
--------------------------

Text-to-Speech generates natural audio from text. NeMo's **Magpie TTS** is a multilingual, codec-based model that supports multiple speakers and languages:

.. code-block:: python

   from nemo.collections.tts.models import MagpieTTSModel
   import soundfile as sf

   # Load model (multilingual 357M, from Hugging Face)
   model = MagpieTTSModel.from_pretrained("nvidia/magpie_tts_multilingual_357m")
   model.eval()

   # Generate speech
   audio, audio_len = model.do_tts(
       transcript="Hello! Welcome to NeMo speech AI.",
       language="en",
   )

   # Save to file
   sf.write("output.wav", audio[0].cpu().numpy(), 22050)
   print("Speech saved to output.wav")


3. Identify Speakers (Diarization)
----------------------------------

Speaker diarization answers "who spoke when?" in multi-speaker audio.

.. code-block:: python

   from nemo.collections.asr.models import SortformerEncLabelModel

   diar_model = SortformerEncLabelModel.from_pretrained("nvidia/diar_streaming_sortformer_4spk-v2")
   diar_model.eval()

   segments = diar_model.diarize(audio=["meeting.wav"], batch_size=1)
   for seg in segments[0]:
       print(seg)  # (begin_seconds, end_seconds, speaker_index)


4. Speech Language Models (SpeechLM2)
-------------------------------------

SpeechLM2 augments large language models with speech understanding. Canary-Qwen combines an ASR encoder with a Qwen LLM:

.. code-block:: python

   from nemo.collections.speechlm2.models import SALM

   model = SALM.from_pretrained('nvidia/canary-qwen-2.5b')

   answer_ids = model.generate(
       prompts=[[{
           "role": "user",
           "content": f"Transcribe the following: {model.audio_locator_tag}",
           "audio": ["speech.wav"],
       }]],
       max_new_tokens=128,
   )
   print(model.tokenizer.ids_to_text(answer_ids[0].cpu()))


What's Next?
------------

Now that you've seen the basics, dive deeper:

- :doc:`key_concepts` — Understand the speech AI fundamentals behind these models
- :doc:`choosing_a_model` — Find the best model for your specific use case
- :doc:`../asr/intro` — Full ASR documentation
- :doc:`../tts/intro` — Full TTS documentation
- :doc:`../asr/speaker_diarization/intro` — Speaker diarization and recognition
- :doc:`../starthere/tutorials` — Tutorial notebooks