Forums

Django-gTTS on pythonanywhere?

Hello!
Before I go cluttering up with a load of logs...
As per the title, I was trying to use it in a very simple web app. I have done everything described here, even the migrations...
Django-Gtts
It appears to be functioning. If I set "controls", I actually do see the control on the page. But it seems greyed out, and unplayable, and I never hear the sound.
I do not see anything untoward in any logs indicating catastrophic failure. I am guessing that it might well be something silly, but it is nothing to do with the browser, as I have tried accessing from different browsers, and on different devices.
Any ideas, please? Could it be an account restriction, perhaps? (Mine is a freebie, as I am only just starting to play around).
Thanks in advance.

Maybe instead of losts of logs, just your last error from the bottom of your error log?

Greetings. Sure...

The only error (apart from favicon that does not bother me) is that it cannot find the mp3 "file" in the static/gTTS folder. However, that said, and if I understand the indications of Django-Gtts correctly, it shouldn't find a file there (unless, of course, that is indeed the cache, which I do not believe). Some undocumented config in settings.py required, perhaps?

2023-01-29 01:39:14,818: Not Found: /static/gTTS/60911935-8b21-4044-a32a-77d7a23dc75a.mp3
2023-01-29 01:39:14,916: Not Found: /favicon.ico
2023-01-29 15:48:28,986: Not Found: /static/gTTS/3f71bb60-7a2e-47d5-8aff-9fbc47daeeb5.mp3
2023-01-29 15:48:29,092: Not Found: /favicon.ico
2023-01-29 15:50:20,286: Not Found: /static/gTTS/3d81edcc-500a-406b-94ed-99050cedee35.mp3
2023-01-29 15:50:26,459: Not Found: /static/gTTS/1a7d3e48-dc21-46f9-8ae2-7a0a12570e12.mp3

Thanks!

It may be an issue with static files mappings, see this help page.

Hmm... No, it is not that. I had already gone through that, but did it all again, to be sure. No dice. Also checked that I have static set up properly on the corresponding WEB tab here, and even added a "static/gTTS" route. Still nothing.
What I don't get is this...
Django-Gtts module is supposed to (I understand) create a cached speech object and pass that to the html directly, but when it comes to the crunch, Django starts looking for the audio object as if it were a pre-saved and uploaded file.
I am not understanding something. Let me clarify, in the project there is already a .cache directory. I would expect it to use that. Is there a need to configure the application to use that directory in settings.py? There is nothing about that, but this is where I would expect it to store that object temporarily. It does not make sense that it is attempting to use a static directory.
Thanks!

I'm not familiar with gTTS -- but it still looks like your code is doing some requests to /static/gTTS/...mp3 which it can't get. If the resources are not to be expected there, maybe it should look for them in a different way.

No worries.
I will start from scratch again, with this, and look for another way to accomplish the objective.

Hello, just popping back with a question, here.
I did some experiments with playsound, and I am finding that there is no way to reproduce sounds. These experiments were done on plain vanilla Python (no Django), just to test, in a virtual environment to which I installed the requirements. I therefore have the following to consider...
Can sounds be reproduced through Pythonanywhere?
That is to say, is there support on the Linux server for playing back mp3? I do not want to go trying to install anything that is not strictly Python, but it may be that a base Linux package (Codec) is not present which playsound (and anything else that attempts to play mp3 files) might use.
PS: Sometime ago I saw a page here where the list of preinstalled features was presented, but cannot seem to find it, now.
Sorry for the bother. Thanks!

There is nothing sound-related installed on our servers as far as I know.

Indeed, it seems that a number of audio (mp3) playback modules for Python on Linux would require:

mpg123 or mpg321

Just doing dpkg -s mpg123 in a bash console confirms that it is not installed. That is as far as I dare go.
Thank you for your assistance.

An mpeg player will not work on PythonAnywhere - there is no sound hardware for it to play on.

No worries! I got it working another way.
Not to be mysterious about it and leave anyone who reads this with the same problem in the dark, it was pretty simple... I used the audio tab in the html template, loaded the mp3 file as a static, and passed it to the browser so that it does the dirty work of playing the sound. The effect is exactly what I wanted, works as expected, and should have done it that way from the start. My excuse?
I am learning...
Thanks.