gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
30.73k stars 2.29k forks source link

Audio component not able to record input from microphone when share=true in launch() #7841

Open EGAILab opened 3 months ago

EGAILab commented 3 months ago

Describe the bug

Gradio version: 4.23.0

Code is taken from: https://www.gradio.app/guides/real-time-speech-recognition

This issue only occurred when setting "share=True" in launch().

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
from transformers import pipeline
import numpy as np

MODEL_NAME = "distil-whisper/distil-large-v2"
# MODEL_NAME = "openai/whisper-base.en"

transcriber = pipeline(
    "automatic-speech-recognition",
    model=MODEL_NAME,
)

def transcribe(audio):
    sr, y = audio
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))
    return transcriber({"sampling_rate": sr, "raw": y})["text"]

demo = gr.Interface(
    transcribe,
    gr.Audio(sources=["microphone"]),
    "text",
)

demo.launch(
    share=True,
)

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/gradio/queueing.py", line 501, in call_prediction
    output = await route_utils.call_process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/gradio/route_utils.py", line 258, in call_process_api
    output = await app.get_blocks().process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/gradio/blocks.py", line 1684, in process_api
    result = await self.call_function(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/gradio/blocks.py", line 1250, in call_function
    prediction = await anyio.to_thread.run_sync(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2134, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 851, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/llm/lib/python3.11/site-packages/gradio/utils.py", line 750, in wrapper
    response = f(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_54649/3198690253.py", line 14, in transcribe
    sr, y = audio
    ^^^^^
TypeError: cannot unpack non-iterable NoneType object

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 4.23.0
gradio_client version: 0.14.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.109.2
ffmpy: 0.3.1
gradio-client==0.14.0 is not installed.
httpx: 0.26.0
huggingface-hub: 0.20.3
importlib-resources: 6.1.1
jinja2: 3.1.3
markupsafe: 2.1.5
matplotlib: 3.8.2
numpy: 1.26.4
orjson: 3.9.13
packaging: 23.2
pandas: 2.2.0
pillow: 10.2.0
pydantic: 2.6.1
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.3.4
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.9.0
uvicorn: 0.27.0.post1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2023.10.0
httpx: 0.26.0
huggingface-hub: 0.20.3
packaging: 23.2
typing-extensions: 4.9.0
websockets: 11.0.3

Severity

Blocking usage of gradio

EGAILab commented 3 months ago

An easier way to replicate, with "share=True", there's no output; and comment that out, the audio can play back.

import gradio as gr

def repeat(audio): return audio

demo = gr.Interface( repeat, gr.Audio(sources=["microphone"]), "audio", )

demo.launch( share=True, )

jiaohuix commented 2 months ago

It works for me!!! I launched the Gradio demo on the server, and set share=True. Locally, I used "ssh -CNg -L 8003:127.0.0.1:8003 root@60.165.238.46 -p 30949". Now, the audio file uploaded locally can be accessed on the server at: /tmp/gradio/631ef51ffcf620fe0b8d5a90e573830b60c890ef/audio.wav.

EGAILab commented 2 months ago

Yes issue is fixed in latest version, feel free to close this, thank you.

cageyoko commented 1 month ago

@EGAILab Hi, I still met a same issue in gradio==4.29.0.

cageyoko commented 1 month ago

I found that the upload delay may be caused by network reasons. When I wait for a while and click submit, the result I want will appear.