Skip to content

Microphone Audio Input bugs #976

@Rikorose

Description

@Rikorose

Describe the bug

I struggle to get audio recording input in chrome on hugging space.

Reproduction

  1. gradio requires (undocumented) external programs
    Unfortunately the required programs are not installed on hugginface spaces and are also not documented.
    When using:
gradio.inputs.Audio(source="microphone", type="numpy")

I get:

Running on local URL:  http://localhost:7860/

To create a public link, set `share=True` in `launch()`.
/home/user/.local/lib/python3.8/site-packages/pydub/utils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
  warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/gradio/routes.py", line 269, in predict
    output = await run_in_threadpool(app.launchable.process_api, body, username)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/home/user/.local/lib/python3.8/site-packages/anyio/to_thread.py", line 28, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
    return await future
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 754, in run
    result = context.run(func, *args)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/interface.py", line 573, in process_api
    prediction, durations = self.process(raw_input)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/interface.py", line 611, in process
    processed_input = [
  File "/home/user/.local/lib/python3.8/site-packages/gradio/interface.py", line 612, in <listcomp>
    input_component.preprocess(raw_input[i])
  File "/home/user/.local/lib/python3.8/site-packages/gradio/inputs.py", line 1173, in preprocess
    return processing_utils.audio_from_file(file_obj.name)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py", line 122, in audio_from_file
    audio = AudioSegment.from_file(filename)
  File "/home/user/.local/lib/python3.8/site-packages/pydub/audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "/home/user/.local/lib/python3.8/site-packages/pydub/utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "/usr/local/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe'

When testing on my local machine (where ffmpeg is installed), two more bugs:
2. Chrome records mono, documentation says result will be of shape (samples, 2)
3. Chrome saves audio as webm/opus, but file extension is still ".wav":
When using

gradio.inputs.Audio(source="microphone", type="filepath")

Which results in the following input (/tmp/audioioc34ntl.wav):

$ ffprobe /tmp/audioioc34ntl.wav
Input #0, matroska,webm, from '/tmp/audioioc34ntl.wav':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)

Unfortunately without ffmpeg I am not able to decode this audio with python. Torchaudio can only decode ogg/opus.

Screenshot

No response

Logs

No response

System Info

Chrome on huggingface space.
Firefox works.

>>> gradio.__version__
'2.9.1'


### Severity

blocker

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions