Saving Text to Speech fails in AI Explorer

Created on 2 December 2024, 17 days ago

When using the "Save as media" feature in the text-to-speech AI explorer, an error always occurs. I think I may be able to offer some info so someone with coding skills can locate the problem easily.
It seems that the module is trying to use the file name as the path to save the file. This is the error I receive:
-----------
An error occurred
The following error occurred while processing your request:

The specified file 'temporary://fileiYLACZ' could not be copied because the destination directory 'public://2024-12/text-to-speech.mp3' is not properly configured. This may be caused by a problem with file or directory permissions.

Of the following exception type:

Drupal\Core\File\Exception\DirectoryNotReadyException
-----------
As you can see it has the full name of the mp3 in the path. I have received similar errors when creating images when I was initially setting the AI modules up . In that case, it had the same error except the file name did not appear in the path. I hope this helps

I confirmed that I am able to connect to openAI successfully, just can't save the files automatically.
-

This is easy to reproduce on my site:

1. Go to AI Explorer text to speech at /admin/config/ai/explorers/ai-text-to-speech.
2. Enter text, press 'Generate', and wait.
3. After 5-10 seconds the error is produced.

---------------------
AI log shows the following (nothing):
Operation Type
text_to_speech
Provider
openai
Model
tts-1
Tags
text_to_speech
ai_api_explorer
Configuration
voice:
alloy

response_format:
mp3

Extra Data
[]
Authored on
Sun, 12/01/2024 - 8:33 pm
-------------------------------------------
My configuration that may be helpful to know:
- Using s3 module to store public and private files.
- Using File field paths module to determine storage path in the public folder.

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jbuttler
  • 🇬🇧United Kingdom MrDaleSmith

    Can you retest this as the AI Explorer has just had a major refactor merged.

  • I just tried to upgrade to beta 3 and it broke my site, so I can't test this at this time. I made a bug report about the upgrade error I received.

  • I upgraded to the dev version based on maintainer recommendation after beta 3 did not work. I am still experiencing the same issue using the latest dev version. A similar error is produced:
    ----------------------
    An error occurred
    The following error occurred while processing your request:

    The specified file 'temporary://fileHP6ttq' could not be copied because the destination directory 's3://2024-12/text-to-speech.mp3' is not properly configured. This may be caused by a problem with file or directory permissions.

    Of the following exception type:

    Drupal\Core\File\Exception\DirectoryNotReadyException

  • 🇬🇧United Kingdom MrDaleSmith

    Just to say, I'm not a maintainer :)

  • I just successfully updated to beta-4 but I am still experiencing this issue.

  • 🇩🇪Germany marcus_johansson

    This will be solved with this comment: https://www.drupal.org/project/ai/issues/3490970#comment-15889122 🐛 Generating Multiple Text-to-Speech Fails in AI Explorer Active .

    The current explorer assumes that public file system exists, which is not always true.

  • 🇬🇧United Kingdom MrDaleSmith

    This issue is resolved by https://www.drupal.org/project/ai/issues/3490970 🐛 Generating Multiple Text-to-Speech Fails in AI Explorer Active but there are some improvements we can make to the process, so I'll do those as part of this issue.

  • Merge request !323Follow-up changes to #3490970 → (Merged) created by MrDaleSmith
  • Pipeline finished with Failed
    9 days ago
    Total: 180s
    #363218
  • Pipeline finished with Success
    9 days ago
    Total: 150s
    #363225
  • Pipeline finished with Success
    9 days ago
    Total: 151s
    #363494
  • Pipeline finished with Canceled
    9 days ago
    Total: 76s
    #363512
  • Pipeline finished with Failed
    9 days ago
    Total: 153s
    #363513
  • Pipeline finished with Success
    9 days ago
    Total: 151s
    #363525
  • 🇩🇪Germany marcus_johansson

    Sorry, should not set to fix - this is merged into dev, but could you test it @jbuttler so it works for you?

  • Well this is interesting! This crashes my site. This may be related to a different issue I recently discovered and made a bug report about ( https://www.drupal.org/project/ai/issues/3492998 🐛 "Queue worker starting to fill out field Cron Job" Breaks Site Active ).

    This seems to cause a memory leak when I try to generate the file in the explorer. I am experiencing a similar memory leak when trying to create a tts file using the automator scheduled cron. I also get the same memory leak occasionally when trying to generate text with the automator, using Open AI. When this has occurred, I have switched to Fireworks for the provider and everything works.

    With the new dev patch, I do not get any files back when trying to create them no matter if I am using the 'Save as Media'. feature or not.

    Error on screen:
    Error message
    Oops, something went wrong. Check your browser's developer console for more details.

    There is no record of this in the site logs. AI logs also show nothing.

    Linux shows memory racing for a minute or so then clears out once it hits the timeout. I attached a screenshot of the process running in linux if this helps.

  • I have an update. I am experiencing this issue in many areas related to using Open AI. When I use an AI Assistant with Open AI, I get the same type of memory issue, eventually resulting in a timeout. This is solved by using a different provider like Groq or Fireworks.
    Audio files only use Open AI. I am thinking this may be a more general Open AI api issue effecting multiple things rather than just related to the audio files.

  • 🇬🇧United Kingdom MrDaleSmith

    My testing was exclusively using OpenAI so I suspect the underlying changes here aren't the issue but that we have a general vulnerability to OpenAI timing out (particular if a cron job is used as you note in https://www.drupal.org/project/ai/issues/3492998 🐛 "Queue worker starting to fill out field Cron Job" Breaks Site Active ). I think we should probably postpone closing this issue but unless other isers report the same issue from the dev branch I do n't think we need to go to the trouble of undoing the merge.

  • I am not sure its a timeout. Open AI seems to never get the request, and I am not currently being billed for the attempts that fail. It seems like some general communication issue. And the memory starts filling up as soon as I send the request, not after a timeout. This behaves the same for audio as it does for AI assistants, and now the automator on node creation when using open AI. I have removed Open AI from most of my functions which allows things to work. I just upgraded past Beta 1 a few days ago and did not experience this, not sure if that is related.

    I can easily reproduce the memory issue but I am not seeing anything in logs about this. Let me know if I can provide any more info or do some testing on my side to help find the cause.

  • Testing Update:

    I have uninstalled several AI sub-modules I was using and that seems to have stabilized the system. The modules I uninstalled were external moderation, seo analyzer, AI search, image alt text, rest facets.

    After removing these, the system seems to be OK (needs more overall testing). The memory leak issue seems to be related to one of the uninstalled modules, and probably not related to this issue. I am not sure which module, or why. I will test re-installing these modules later to see if I can find the problem. I suspect it to be external moderation calling OpenAI. But I also recently installed AI search and image alt text so I cant rule those out.

    I reinstalled the dev version of AI. I was able to successfully save audio to the media library using the AI explorer. This is the first time I have been able to do this.
    Each time I enter a new prompt, I get the correct audio back, and the new audio is saved to the media library. Previously I only received duplicates of old submissions.

    It seems like this issue has been resolved with the dev version I tested "dev-1.0.x 42f0fea". In the end the only changes I made on my side were uninstalling the modules above, then testing the dev version.

  • 🇩🇪Germany marcus_johansson

    Its for sure external moderation, we should add some validation and description there. OpenAI uses the moderation endpoint by default.

    The external moderation is just for adding one providers moderation endpoint over another provider, so if you add OpenAI over OpenAI it might cause circular dependency.

    But this is a good bug catch and should be fixed - I created an issue for it here: https://www.drupal.org/project/ai/issues/3493419 🐛 Do not allow for the same providers moderation to be used in external moderation Active

  • 🇩🇪Germany marcus_johansson

    I think we can set this to fixed now?

  • Yes I think this is fixed in the dev version. Thanks for your help!

Production build 0.71.5 2024