travisvn / openai-edge-tts

Text-to-speech API endpoint compatible with OpenAI's TTS API endpoint, using Microsoft Edge TTS to generate speech for free locally
https://tts.travisvn.com
GNU General Public License v3.0
110 stars 17 forks source link

ffmpeg not installed when using Kubernetes Deployment #8

Open andrptrc opened 3 days ago

andrptrc commented 3 days ago

When deploying the Docker image on a Kubernetes cluster the server have this error where ffmpeg package is missing.

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/utils.py", line 27, in decorated_function
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/app/server.py", line 40, in text_to_speech
    output_file_path = generate_speech(text, voice, response_format, speed)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/tts_handler.py", line 55, in generate_speech
    return asyncio.run(_generate_audio(text, voice, response_format, speed))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/app/tts_handler.py", line 48, in _generate_audio
    subprocess.run(ffmpeg_command, check=True)
  File "/usr/local/lib/python3.12/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Here is my yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: openai-edge-tts-deployment
  labels:
    app: openai-edge-tts
spec:
  replicas: 1
  selector:
    matchLabels:
      app: openai-edge-tts
  template:
    metadata:
      labels:
        app: openai-edge-tts
    spec:
      containers:
      - name: openai-edge-tts
        image: travisvn/openai-edge-tts:latest
        ports:
        - containerPort: 5050
        env:
        - name: API_KEY
          value: your_api_key_here
        - name: PORT
          value: "5050"
        - name: DEFAULT_VOICE
          value: fr-FR-RemyMultilingualNeural
        - name: DEFAULT_RESPONSE_FORMAT
          value: wav
        - name: DEFAULT_SPEED
          value: "1.0"
        - name: DEFAULT_LANGUAGE
          value: fr-FR
        - name: REQUIRE_API_KEY
          value: "True"

Is the package installation missing from the Dockerfile or maybe is it the python3.12-slim that does not have it?

travisvn commented 3 days ago

ffmpeg must be installed on the server hosting the openai-edge-tts project

So running sudo apt install ffmpeg or brew install ffmpeg and making sure it's accessible through the subprocess command in Python (most likely aligning your $PATH so that it includes ffmpeg)

https://github.com/travisvn/openai-edge-tts/blob/main/app/tts_handler.py#L62

I am unsure of the use case in your situation that adds Kubernetes to the mix, but the spirit of this project is for non-enterprise use.

If you'd like to discuss non-personal use for this project, feel free to contact me github@travisvn.com

andrptrc commented 2 days ago

I am running the project on a Kubernetes server for a school project, and every time I start the pod, I need to connect to the pod and run the apt install ffmpeg. I thought it was simply a missing line in the Dockerfile that should be run before launching the python script.

But if you think it should be done on the host machine directly in most use cases, it is not a problem :)