What I’m trying to do: I had a code that was working very well. which is this one:
audio = row[‘audio’]
audio_bytes = audio.get_bytes()
filename = f’temp_audio_{user[“email”]}’
print(filename) #write the file to disk
with open(filename, ‘wb+’) as f:
f.write(audio_bytes)
# convert audio to mp3 format
song = AudioSegment.from_file(filename)
mp3_filename = ‘new_audio.mp3’
song.export(mp3_filename, format=“mp3”)
#read the file before sending it to open ai
audio_file = open(mp3_filename, "rb")
which was necessary for converting the file to mp3. now is giving me this error:
I replied just now to a similar post. I think it is relevant in this case, too.
Are you sure the code that worked is the same as what you’ve just pasted? As far as I remember, you’ve never been able to just write to a file in Anvil. There is some ephemeral disk splace you can use in /tmp so maybe your filename was different before?
I’m not able to test it on my system at the moment, but if something has changed you might do better to create a BytesIO object instead of saving to disk (see my link above), or consider doing it over an Uplink.
Thanks a lot for your help. I tried the BytesIO but openai does not work with data bytes. I need to send the audio to openAI for transcription. Any other suggestion?
Im in the professional plan. I think is that over the weekend I had upgrade my build to machine learning for some libraries. Maybe in this build is only read-only.
will try this: with open(‘/tmp/testingfile’, ‘wb+’) as f:
I am running a the hosted one which is the default one right?
When I say i upgraded my build i am talking about the servers build options of anvil, “standard” “machine learning” and so on. I think the machine learning is read-only.
EDIT: I am pretty positive is that, i went back to my old build “standard” and the same code now works…
Can we get help from the devs to make machine learning build read and write temporary files?
EDIT II: apparently has something to do with the certifi library, there is a vulnerability found, which ask you to install the last version of certifi. Once you install this, for some reason that I cant still understand you cant write any file into the temporary folder… this happens even in Standard mode…
EDIT III: Finally!, it seems that one of the updates for builds that I was using in my last version of the app improves security of the server (I guess) and was not letting me save the file like this: ‘file’, only like this: ‘’/tmp/file" which was not happening before the update. This was suggested by david.wytie but I am not sure why i did not worked before, I uninstalled all the packages and installed them again and tried with ‘/tmp/’ and it worked. Thanks.