# How do we provide AUDIO Examples when using Blocks?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%3E%5C
**Category:** 🔒 Gradio\
**Created:** [May 1, 2023, 9:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346 "2023-05-01T21:42:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 1, 2023, 9:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F1 "2023-05-01T21:42:53Z")

</div>

**Update: Editing question now that I seem to be on the correct track, but having trouble with Audio specifically. If you could scroll down my 3rd message in this thread, I’d appreciate it. Thanks.**

When we’re not using `gr.Interface(...)`, but rather using `gr.Blocks()`, how/where do we… specify examples?

I’m not finding any information in the [Key Features Guide](https://gradio.app/key-features/#example-inputs) or [More on Examples](https://gradio.app/more-on-examples/) for the case of Blocks, or the docs page for [Blocks](https://gradio.app/docs/#blocks).

I’m also not seeing `examples=` on the list of supported kwargs to [gr.Blocks()](https://gradio.app/docs/#blocks). And there doesn’t seem to be any `gr.Example()` object; the docs go from “Dropdown” to “File”, skipping the letter E.

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 1, 2023, 9:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F2 "2023-05-01T21:55:27Z")

</div>

Wow, ok, just found the actual [gr.Examples](https://gradio.app/docs/#examples) object! lol. Didn’t see it further down the screen.

You know, it might be a good idea to mention its existence somewhere in the “More on Examples” page. 😉

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 1, 2023, 10:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F3 "2023-05-01T22:31:58Z")

</div>

**UPDATE:** Ok, I’m having a hard time specifying Audio examples. Maybe I just need to search around for examples. I’m only finding Images and text.

I load in a couple audio waveforms, convert them to channels-last PCM int 16 values, and supply as in the examples string, a tuple of `( sample_rate, waveform_numpy_int16 )`.

But I’m getting this error:

```auto
    gr.Examples(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/helpers.py", line 55, in create_examples
    examples_obj = Examples(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/helpers.py", line 228, in __init__
    self.dataset = components.Dataset(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/components.py", line 6136, in __init__
    example[i] = component.as_example(ex)
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/components.py", line 2563, in as_example
    return Path(input_data).name if input_data else ""
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 960, in __new__
    self = cls._from_parts(args)
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 594, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 578, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not tuple

```

But Audio objects pass tuples to their routines right? I tried just passing in the waveform, but my processing routine had expected tuples so it didn’t work.

If I try using filename strings as examples, then when they get to my processing function the variable there is `None` instead of the string I provided. 🤷

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 1, 2023, 11:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F4 "2023-05-01T23:44:04Z")

</div>

Ok, one workaround is to turn off caching, outputs, fn, and execute on click. Then the inputs get populated and users can just go press Submit. Works for now.

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [May 2, 2023, 2:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F5 "2023-05-02T14:11:54Z")

</div>

Hi @drscotthawley !

You should be able to pass in a filepath to a `.wav` or `.mp3` file. Here is an example:

> <https://github.com/gradio-app/gradio/blob/main/demo/unispeech-speaker-verification/run.py#L97>

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 3, 2023, 3:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F6 "2023-05-03T15:20:00Z")

</div>

@freddyaboulton thanks; i’ll have to try converting your example from Interface to Blocks,…because _despite_ my _trying_ to pass in strings, they arrive at the function being called as None instead of the string.  
This only happens when `cache_examples` or `run_on_click` are enabled. When those are disabled, then the string arrives correctly and the user can manually press the Submit button.

Or perhaps the fact that I’m using the queue leads to unexpected behavior?

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 3, 2023, 3:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F7 "2023-05-03T15:39:27Z")

</div>

@freddyaboulton I get similar behavior when I convert your example to Blocks:

```python
with gr.Blocks() as demo: 
 
    inputs = [
        gr.Audio(source="microphone", type="filepath", optional=True, label="Speaker #1"),
        gr.Audio(source="microphone", type="filepath", optional=True, label="Speaker #2"),
    ]
    output = gr.HTML(label="")

    examples = [
        #["samples/cate_blanch.mp3", "samples/cate_blanch_2.mp3"], # I didn't have these files but you get the idea
        ["/content/metal_trap.wav","/content/metal_trap.wav",]
    ]
    gr.Examples( fn=similarity_fn, examples=examples, inputs=inputs, outputs=output,
            run_on_click=True, # <----- **** RIGHT HERE. Enabling this causes None to arrive at the inputs when an example is clicked.
            )
    submit_btn = gr.Button("Submit")
    submit_btn.click(fn=similarity_fn, inputs=inputs, outputs=output)

if __name__ == " __main__":
    demo.launch()

```

I notice [this GitHub Issue](https://github.com/gradio-app/gradio/issues/3980) shows another user reporting a similar problem for Blocks.

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [May 3, 2023, 3:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F8 "2023-05-03T15:52:08Z")

</div>

Ok we’ll look into it! Thank you @drscotthawley

---

<div class="post-metadata">

**Author:** ![drscotthawley](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drscotthawley/32/62161_2.png) [@drscotthawley](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrscotthawley)%5C
**Post date:** [May 13, 2023, 8:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-do-we-provide-audio-examples-when-using-blocks%2F38346%2F9 "2023-05-13T20:54:58Z")

</div>

@freddyaboulton Any movement on this?
