{"record":{"id":"ee6c0c9fd2b234b5","repo":"binary-husky/gpt_academic","slug":"ffmpeg-edgetts-https-github-com-j","errorCode":null,"errorMessage":"ffmpeg未安装，无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydub#getting-ffmpeg-set-up`","messagePattern":"ffmpeg未安装，无法处理EdgeTTS音频。安装方法见`https://github\\.com/jiaaro/pydub#getting-ffmpeg-set-up`","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"shared_utils/fastapi_server.py","lineNumber":228,"sourceCode":"                        import edge_tts\n                        import wave\n                        import uuid\n                        from pydub import AudioSegment\n                        json = await request.json()\n                        voice = get_conf(\"EDGE_TTS_VOICE\")\n                        tts = edge_tts.Communicate(text=json['text'], voice=voice)\n                        temp_folder = tempfile.gettempdir()\n                        temp_file_name = str(uuid.uuid4().hex)\n                        temp_file = os.path.join(temp_folder, f'{temp_file_name}.mp3')\n                        await tts.save(temp_file)\n                        try:\n                            mp3_audio = AudioSegment.from_file(temp_file, format=\"mp3\")\n                            mp3_audio.export(temp_file, format=\"wav\")\n                            with open(temp_file, 'rb') as wav_file: t = wav_file.read()\n                            os.remove(temp_file)\n                            return Response(content=t)\n                        except:\n                            raise RuntimeError(\"ffmpeg未安装，无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydub#getting-ffmpeg-set-up`\")\n                    if TTS_TYPE == \"LOCAL_SOVITS_API\":\n                        # Forward the request to the target service\n                        TARGET_URL = get_conf(\"GPT_SOVITS_URL\")\n                        body = await request.body()\n                        resp = await client.post(TARGET_URL, content=body, timeout=60)\n                        # Return the response from the target service\n                        return Response(content=resp.content, status_code=resp.status_code, headers=dict(resp.headers))\n                except httpx.RequestError as e:\n                    raise HTTPException(status_code=400, detail=f\"Request to the target service failed: {str(e)}\")\n        @gradio_app.post(\"/vits\")\n        async def forward_post_request(request: Request):\n            return await forward_request(request, \"POST\")\n\n    # --- --- app_lifespan --- ---\n    from contextlib import asynccontextmanager\n    @asynccontextmanager\n    async def app_lifespan(app):\n        async def startup_gradio_app():","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/shared_utils/fastapi_server.py#L210-L246","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Restart the server after installing so the new PATH is picked up.","Verify with 'ffmpeg -version' run in the same environment/user as the server.","If ffmpeg is present but the error persists, log the original exception — the bare except may be masking the real cause."],"exampleFix":"# before\nexcept:\n    raise RuntimeError(\"ffmpeg未安装...\")\n\n# after: preserve the true cause\nexcept Exception as e:\n    logger.error(f\"EdgeTTS audio conversion failed: {e!r}\")\n    raise RuntimeError(\"ffmpeg未安装，无法处理EdgeTTS音频。...\") from e","handlingStrategy":"validation","validationCode":"import shutil\nif shutil.which('ffmpeg') is None:\n    raise EnvironmentError('ffmpeg not on PATH — install before enabling EDGE_TTS')","typeGuard":null,"tryCatchPattern":"try:\n    wav = convert_mp3_to_wav(temp_file)\nexcept RuntimeError as e:\n    if 'ffmpeg' in str(e):\n        install_ffmpeg_hint(); alert_operator()","preventionTips":["Install ffmpeg and verify with shutil.which('ffmpeg') at service startup.","Include ffmpeg in the deployment image (apt-get install -y ffmpeg).","Log the original pydub exception, not just the assumed diagnosis."],"tags":["tts","ffmpeg","pydub","dependencies","edge-tts"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}