Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Streaming audio data","local":"streaming-audio-data","sections":[],"depth":1}"> | |
| <link href="/docs/audio-course/pr_201/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/entry/start.367c4d78.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/scheduler.f7e1785c.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/singletons.0d70d4cc.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/index.279db187.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/paths.274f629d.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/entry/app.4c54ebf9.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/index.9f8f0838.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/nodes/0.e329f606.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/nodes/10.6375df16.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/CodeBlock.b3510e34.js"> | |
| <link rel="modulepreload" href="/docs/audio-course/pr_201/en/_app/immutable/chunks/EditOnGithub.5a9bb8c5.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Streaming audio data","local":"streaming-audio-data","sections":[],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="streaming-audio-data" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#streaming-audio-data"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Streaming audio data</span></h1> <p data-svelte-h="svelte-n8v3tf">One of the biggest challenges faced with audio datasets is their sheer size. A single minute of uncompressed CD-quality audio (44.1kHz, 16-bit) | |
| takes up a bit more than 5 MB of storage. Typically, an audio dataset would contains hours of recordings.</p> <p data-svelte-h="svelte-nayksx">In the previous sections we used a very small subset of MINDS-14 audio dataset, however, typical audio datasets are much larger. | |
| For example, the <code>xs</code> (smallest) configuration of <a href="https://huggingface.co/datasets/speechcolab/gigaspeech" rel="nofollow">GigaSpeech from SpeechColab</a> | |
| contains only 10 hours of training data, but takes over 13GB of storage space for download and preparation. So what | |
| happens when we want to train on a larger split? The full <code>xl</code> configuration of the same dataset contains 10,000 hours of | |
| training data, requiring over 1TB of storage space. For most of us, this well exceeds the specifications of a typical | |
| hard drive disk. Do we need to fork out and buy additional storage? Or is there a way we can train on these datasets with no disk space constraints?</p> <p data-svelte-h="svelte-1cmn14y">🤗 Datasets comes to the rescue by offering the <a href="https://huggingface.co/docs/datasets/stream" rel="nofollow">streaming mode</a>. Streaming allows us to load the data progressively as | |
| we iterate over the dataset. Rather than downloading the whole dataset at once, we load the dataset one example at a time. | |
| We iterate over the dataset, loading and preparing examples on the fly when they are needed. This way, we only ever | |
| load the examples that we’re using, and not the ones that we’re not! | |
| Once we’re done with an example sample, we continue iterating over the dataset and load the next one.</p> <p data-svelte-h="svelte-1doba0z">Streaming mode has three primary advantages over downloading the entire dataset at once:</p> <ul data-svelte-h="svelte-dy12ia"><li>Disk space: examples are loaded to memory one-by-one as we iterate over the dataset. Since the data is not downloaded | |
| locally, there are no disk space requirements, so you can use datasets of arbitrary size.</li> <li>Download and processing time: audio datasets are large and need a significant amount of time to download and process. | |
| With streaming, loading and processing is done on the fly, meaning you can start using the dataset as soon as the first | |
| example is ready.</li> <li>Easy experimentation: you can experiment on a handful of examples to check that your script works without having to | |
| download the entire dataset.</li></ul> <p data-svelte-h="svelte-dhhyuw">There is one caveat to streaming mode. When downloading a full dataset without streaming, both the raw data and processed | |
| data are saved locally to disk. If we want to re-use this dataset, we can directly load the processed data from disk, | |
| skipping the download and processing steps. Consequently, we only have to perform the downloading and processing | |
| operations once, after which we can re-use the prepared data.</p> <p data-svelte-h="svelte-1b0tiu9">With streaming mode, the data is not downloaded to disk. Thus, neither the downloaded nor pre-processed data are cached. | |
| If we want to re-use the dataset, the streaming steps must be repeated, with the audio files loaded and processed on | |
| the fly again. For this reason, it is advised to download datasets that you are likely to use multiple times.</p> <p data-svelte-h="svelte-16vl0hj">How can you enable streaming mode? Easy! Just set <code>streaming=True</code> when you load your dataset. The rest will be taken | |
| care for you:</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->gigaspeech = load_dataset(<span class="hljs-string">"speechcolab/gigaspeech"</span>, <span class="hljs-string">"xs"</span>, streaming=<span class="hljs-literal">True</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-182p0qe">Just like we applied preprocessing steps to a downloaded subset of MINDS-14, you can do the same preprocessing with a | |
| streaming dataset in the exactly the same manner.</p> <p data-svelte-h="svelte-1e6b0ye">The only difference is that you can no longer access individual samples using Python indexing (i.e. <code>gigaspeech["train"][sample_idx]</code>). | |
| Instead, you have to iterate over the dataset. Here’s how you can access an example when streaming a dataset:</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-built_in">next</span>(<span class="hljs-built_in">iter</span>(gigaspeech[<span class="hljs-string">"train"</span>]))<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1mvdyro"><strong>Output:</strong></p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->{ | |
| <span class="hljs-string">"segment_id"</span>: <span class="hljs-string">"YOU0000000315_S0000660"</span>, | |
| <span class="hljs-string">"speaker"</span>: <span class="hljs-string">"N/A"</span>, | |
| <span class="hljs-string">"text"</span>: <span class="hljs-string">"AS THEY'RE LEAVING <COMMA> CAN KASH PULL ZAHRA ASIDE REALLY QUICKLY <QUESTIONMARK>"</span>, | |
| <span class="hljs-string">"audio"</span>: { | |
| <span class="hljs-string">"path"</span>: <span class="hljs-string">"xs_chunks_0000/YOU0000000315_S0000660.wav"</span>, | |
| <span class="hljs-string">"array"</span>: <span class="hljs-built_in">array</span>( | |
| <span class="hljs-selector-attr">[0.0005188, 0.00085449, 0.00012207, ..., 0.00125122, 0.00076294, 0.00036621]</span> | |
| ), | |
| <span class="hljs-string">"sampling_rate"</span>: <span class="hljs-number">16000</span>, | |
| }, | |
| <span class="hljs-string">"begin_time"</span>: <span class="hljs-number">2941.89</span>, | |
| <span class="hljs-string">"end_time"</span>: <span class="hljs-number">2945.07</span>, | |
| <span class="hljs-string">"audio_id"</span>: <span class="hljs-string">"YOU0000000315"</span>, | |
| <span class="hljs-string">"title"</span>: <span class="hljs-string">"Return to Vasselheim | Critical Role: VOX MACHINA | Episode 43"</span>, | |
| <span class="hljs-string">"url"</span>: <span class="hljs-string">"https://www.youtube.com/watch?v=zr2n1fLVasU"</span>, | |
| <span class="hljs-string">"source"</span>: <span class="hljs-number">2</span>, | |
| <span class="hljs-string">"category"</span>: <span class="hljs-number">24</span>, | |
| <span class="hljs-string">"original_full_path"</span>: <span class="hljs-string">"audio/youtube/P0004/YOU0000000315.opus"</span>, | |
| }<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-k3iau9">If you’d like to preview several examples from a large dataset, use the <code>take()</code> to get the first n elements. Let’s grab | |
| the first two examples in the gigaspeech dataset:</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->gigaspeech_head = gigaspeech[<span class="hljs-string">"train"</span>].take(<span class="hljs-number">2</span>) | |
| <span class="hljs-built_in">list</span>(gigaspeech_head)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1mvdyro"><strong>Output:</strong></p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->[ | |
| { | |
| <span class="hljs-string">"segment_id"</span>: <span class="hljs-string">"YOU0000000315_S0000660"</span>, | |
| <span class="hljs-string">"speaker"</span>: <span class="hljs-string">"N/A"</span>, | |
| <span class="hljs-string">"text"</span>: <span class="hljs-string">"AS THEY'RE LEAVING <COMMA> CAN KASH PULL ZAHRA ASIDE REALLY QUICKLY <QUESTIONMARK>"</span>, | |
| <span class="hljs-string">"audio"</span>: { | |
| <span class="hljs-string">"path"</span>: <span class="hljs-string">"xs_chunks_0000/YOU0000000315_S0000660.wav"</span>, | |
| <span class="hljs-string">"array"</span>: array( | |
| [ | |
| <span class="hljs-number">0.0005188</span>, | |
| <span class="hljs-number">0.00085449</span>, | |
| <span class="hljs-number">0.00012207</span>, | |
| ..., | |
| <span class="hljs-number">0.00125122</span>, | |
| <span class="hljs-number">0.00076294</span>, | |
| <span class="hljs-number">0.00036621</span>, | |
| ] | |
| ), | |
| <span class="hljs-string">"sampling_rate"</span>: <span class="hljs-number">16000</span>, | |
| }, | |
| <span class="hljs-string">"begin_time"</span>: <span class="hljs-number">2941.89</span>, | |
| <span class="hljs-string">"end_time"</span>: <span class="hljs-number">2945.07</span>, | |
| <span class="hljs-string">"audio_id"</span>: <span class="hljs-string">"YOU0000000315"</span>, | |
| <span class="hljs-string">"title"</span>: <span class="hljs-string">"Return to Vasselheim | Critical Role: VOX MACHINA | Episode 43"</span>, | |
| <span class="hljs-string">"url"</span>: <span class="hljs-string">"https://www.youtube.com/watch?v=zr2n1fLVasU"</span>, | |
| <span class="hljs-string">"source"</span>: <span class="hljs-number">2</span>, | |
| <span class="hljs-string">"category"</span>: <span class="hljs-number">24</span>, | |
| <span class="hljs-string">"original_full_path"</span>: <span class="hljs-string">"audio/youtube/P0004/YOU0000000315.opus"</span>, | |
| }, | |
| { | |
| <span class="hljs-string">"segment_id"</span>: <span class="hljs-string">"AUD0000001043_S0000775"</span>, | |
| <span class="hljs-string">"speaker"</span>: <span class="hljs-string">"N/A"</span>, | |
| <span class="hljs-string">"text"</span>: <span class="hljs-string">"SIX TOMATOES <PERIOD>"</span>, | |
| <span class="hljs-string">"audio"</span>: { | |
| <span class="hljs-string">"path"</span>: <span class="hljs-string">"xs_chunks_0000/AUD0000001043_S0000775.wav"</span>, | |
| <span class="hljs-string">"array"</span>: array( | |
| [ | |
| <span class="hljs-number">1.43432617</span>e-03, | |
| <span class="hljs-number">1.37329102</span>e-03, | |
| <span class="hljs-number">1.31225586</span>e-03, | |
| ..., | |
| <span class="hljs-number">-6.10351562</span>e-05, | |
| <span class="hljs-number">-1.22070312</span>e-04, | |
| <span class="hljs-number">-1.83105469</span>e-04, | |
| ] | |
| ), | |
| <span class="hljs-string">"sampling_rate"</span>: <span class="hljs-number">16000</span>, | |
| }, | |
| <span class="hljs-string">"begin_time"</span>: <span class="hljs-number">3673.96</span>, | |
| <span class="hljs-string">"end_time"</span>: <span class="hljs-number">3675.26</span>, | |
| <span class="hljs-string">"audio_id"</span>: <span class="hljs-string">"AUD0000001043"</span>, | |
| <span class="hljs-string">"title"</span>: <span class="hljs-string">"Asteroid of Fear"</span>, | |
| <span class="hljs-string">"url"</span>: <span class="hljs-string">"http//www.archive.org/download/asteroid_of_fear_1012_librivox/asteroid_of_fear_1012_librivox_64kb_mp3.zip"</span>, | |
| <span class="hljs-string">"source"</span>: <span class="hljs-number">0</span>, | |
| <span class="hljs-string">"category"</span>: <span class="hljs-number">28</span>, | |
| <span class="hljs-string">"original_full_path"</span>: <span class="hljs-string">"audio/audiobook/P0011/AUD0000001043.opus"</span>, | |
| }, | |
| ]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1jjur40">Streaming mode can take your research to the next level: not only are the biggest datasets accessible to you, but you | |
| can easily evaluate systems over multiple datasets in one go without worrying about your disk space. Compared to | |
| evaluating on a single dataset, multi-dataset evaluation gives a better metric for the generalisation abilities of a | |
| speech recognition system (c.f. End-to-end Speech Benchmark (ESB)).</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter1/streaming.mdx" target="_blank"><span data-svelte-h="svelte-1kd6by1"><</span> <span data-svelte-h="svelte-x0xyl0">></span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_yq3w38 = { | |
| assets: "/docs/audio-course/pr_201/en", | |
| base: "/docs/audio-course/pr_201/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/audio-course/pr_201/en/_app/immutable/entry/start.367c4d78.js"), | |
| import("/docs/audio-course/pr_201/en/_app/immutable/entry/app.4c54ebf9.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 10], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 22.2 kB
- Xet hash:
- a8f8c3c36c8cad984b77a81bbcbd5f540aa4c4e57333e66b5f7f76e548885be2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.