diff --git a/.changeset/puny-bats-smell.md b/.changeset/puny-bats-smell.md new file mode 100644 index 000000000000..9674004f0873 --- /dev/null +++ b/.changeset/puny-bats-smell.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +feat:Raise WasmUnsupportedError for ffmpeg usage on Lite diff --git a/gradio/components/audio.py b/gradio/components/audio.py index 34f7f3986cac..45f8b0e25d16 100644 --- a/gradio/components/audio.py +++ b/gradio/components/audio.py @@ -16,7 +16,7 @@ from gradio_client.documentation import document from pydub import AudioSegment -from gradio import processing_utils, utils +from gradio import processing_utils, utils, wasm_utils from gradio.components.base import Component, StreamingInput, StreamingOutput from gradio.data_classes import FileData, FileDataDict, MediaStreamChunk from gradio.events import Events @@ -311,6 +311,10 @@ def postprocess( @staticmethod def _convert_to_adts(data: bytes): + if wasm_utils.IS_WASM: + raise wasm_utils.WasmUnsupportedError( + "Audio streaming is not supported in the Wasm mode." + ) segment = AudioSegment.from_file(io.BytesIO(data)) buffer = io.BytesIO() diff --git a/gradio/components/video.py b/gradio/components/video.py index 8464f3a57289..34c0006f242b 100644 --- a/gradio/components/video.py +++ b/gradio/components/video.py @@ -424,6 +424,11 @@ def example_value(self) -> Any: @staticmethod def get_video_duration_ffprobe(filename: str): + if wasm_utils.IS_WASM: + raise wasm_utils.WasmUnsupportedError( + "ffprobe is not supported in the Wasm mode." + ) + result = subprocess.run( [ "ffprobe", @@ -454,6 +459,11 @@ def get_video_duration_ffprobe(filename: str): @staticmethod async def async_convert_mp4_to_ts(mp4_file, ts_file): + if wasm_utils.IS_WASM: + raise wasm_utils.WasmUnsupportedError( + "Streaming is not supported in the Wasm mode." + ) + ff = FFmpeg( # type: ignore inputs={mp4_file: None}, outputs={ diff --git a/gradio/processing_utils.py b/gradio/processing_utils.py index b003ec57d83f..c04ec7685716 100644 --- a/gradio/processing_utils.py +++ b/gradio/processing_utils.py @@ -628,6 +628,12 @@ def audio_from_file( else "" ) raise RuntimeError(msg) from e + except OSError as e: + if wasm_utils.IS_WASM: + raise wasm_utils.WasmUnsupportedError( + "Audio format conversion is not supported in the Wasm mode." + ) from e + raise e if crop_min != 0 or crop_max != 100: audio_start = len(audio) * crop_min / 100 audio_end = len(audio) * crop_max / 100 @@ -641,6 +647,10 @@ def audio_from_file( def audio_to_file(sample_rate, data, filename, format="wav"): if format == "wav": data = convert_to_16_bit_wav(data) + elif wasm_utils.IS_WASM: + raise wasm_utils.WasmUnsupportedError( + "Audio formats other than .wav are not supported in the Wasm mode." + ) audio = AudioSegment( data.tobytes(), frame_rate=sample_rate,