binary-husky/gpt_academic · error · RuntimeError

ffmpeg未安装,无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydu

Error message

ffmpeg未安装,无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydub#getting-ffmpeg-set-up`

What it means

In the TTS endpoint for TTS_TYPE == 'EDGE_TTS': the mp3 produced by edge-tts is converted to wav using pydub.AudioSegment, which shells out to ffmpeg. The bare except around from_file/export assumes any failure means ffmpeg is missing and raises RuntimeError pointing at pydub's ffmpeg setup docs — a diagnosis that can also swallow unrelated audio errors.

Source

Thrown at shared_utils/fastapi_server.py:228

                        import edge_tts
                        import wave
                        import uuid
                        from pydub import AudioSegment
                        json = await request.json()
                        voice = get_conf("EDGE_TTS_VOICE")
                        tts = edge_tts.Communicate(text=json['text'], voice=voice)
                        temp_folder = tempfile.gettempdir()
                        temp_file_name = str(uuid.uuid4().hex)
                        temp_file = os.path.join(temp_folder, f'{temp_file_name}.mp3')
                        await tts.save(temp_file)
                        try:
                            mp3_audio = AudioSegment.from_file(temp_file, format="mp3")
                            mp3_audio.export(temp_file, format="wav")
                            with open(temp_file, 'rb') as wav_file: t = wav_file.read()
                            os.remove(temp_file)
                            return Response(content=t)
                        except:
                            raise RuntimeError("ffmpeg未安装,无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydub#getting-ffmpeg-set-up`")
                    if TTS_TYPE == "LOCAL_SOVITS_API":
                        # Forward the request to the target service
                        TARGET_URL = get_conf("GPT_SOVITS_URL")
                        body = await request.body()
                        resp = await client.post(TARGET_URL, content=body, timeout=60)
                        # Return the response from the target service
                        return Response(content=resp.content, status_code=resp.status_code, headers=dict(resp.headers))
                except httpx.RequestError as e:
                    raise HTTPException(status_code=400, detail=f"Request to the target service failed: {str(e)}")
        @gradio_app.post("/vits")
        async def forward_post_request(request: Request):
            return await forward_request(request, "POST")

    # --- --- app_lifespan --- ---
    from contextlib import asynccontextmanager
    @asynccontextmanager
    async def app_lifespan(app):
        async def startup_gradio_app():

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Install ffmpeg and ensure it is on the service's PATH (pydub docs link in the message; apt install ffmpeg / brew install ffmpeg / Windows build).
  2. Restart the server after installing so the new PATH is picked up.
  3. Verify with 'ffmpeg -version' run in the same environment/user as the server.
  4. If ffmpeg is present but the error persists, log the original exception — the bare except may be masking the real cause.

Example fix

# before
except:
    raise RuntimeError("ffmpeg未安装...")

# after: preserve the true cause
except Exception as e:
    logger.error(f"EdgeTTS audio conversion failed: {e!r}")
    raise RuntimeError("ffmpeg未安装,无法处理EdgeTTS音频。...") from e
Defensive patterns

Strategy: validation

Validate before calling

import shutil
if shutil.which('ffmpeg') is None:
    raise EnvironmentError('ffmpeg not on PATH — install before enabling EDGE_TTS')

Try / catch

try:
    wav = convert_mp3_to_wav(temp_file)
except RuntimeError as e:
    if 'ffmpeg' in str(e):
        install_ffmpeg_hint(); alert_operator()

Prevention

When it happens

Trigger: Hitting the /vits or TTS endpoint with TTS_TYPE='EDGE_TTS' when ffmpeg is not on PATH: AudioSegment.from_file raises CouldntDecodeError, the except converts it to this RuntimeError. Also fires if edge-tts wrote a corrupt/empty file for another reason.

Common situations: Fresh Windows/Linux box without ffmpeg installed; Docker image lacking ffmpeg; PATH not including ffmpeg in the service environment; edge-tts upstream breakage producing non-mp3 bytes that then fail decode.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/ee6c0c9fd2b234b5. Report an issue: GitHub.