I want to build a YouTube transcribing application.
I want the user to input the video link, and download the video as an MP3 file. After that, I want to create a background task that reads that file and feeds it to the Whisper model.
The Whisper model doesn’t read Bytes type objects, that is the error that I’m getting.
Is there any way I can store the thus created MP3 file and pass it to Whisper?
As far as my understanding goes, files in the “tmp” folder can only be used inside with-open blocks; so how would I create the file, and while the file is open, pass it to Whisper (since Whisper only reads file-type objects)?
import anvil.media
media_object = a_function_that_gets_your_youtube_file_as_anvil_media(url_i_guess)
with anvil.media.TempFile(media_object) as file_name:
# Now there is a file in filesystem containing contents of media_object.
# The file_name variable is a string of its full path.
some_function_that_uses_whisper_to_do_stuff(file_name)
Put your use of the temporary file name inside a function that uses whisper, then when that function returns, it will complete the with block and get rid of the temporary file.