How to display multiple audio files in google colab? - audio

I would like to display multiple audio files in google colab, but I found that only one is possible in one codeblock. Therefore I was thinking, whether I could generate code blocks with a given text.
Something like:
for i in range(0,4):
create_code_block("display.Audio(str(sound_paths[" + str(i) + "]))")

You mistake display.Audio for displaying. It's just creating Audio objects.
You need this instead.
display.display(display.Audio(filename))
And try to avoid overwrite the display. Don't do this
from IPython import display # don't do
Because you cannot use the old display anymore.
Normally you can just
display(Audio(...))
Now you would need to use
display.display(display.Audio(...))

Related

Add Bookmarks to pdf using Pymupdf

How to add Bookmarks to pdf using Pymupdf. I have seen many ways using PyPDF2 but since I'm already using pymupdf for other annotations I would prefer pymupdf for adding bookmarks. Also would like to highlight the text and add bookmarks to it.
You cannot add single bookmarks like you can in other packages.
If you have looked at the details there - or rather in the respective PDF specification, this is an overly / unnecessarily complex task.
PyMuPDF in contrast has this simple approach to offer:
Prepare a Python list that looks like a traditional table of contents (TOC):
Every line in the list contains the hierarchy level, the text to display and the page number. Optionally also some information where on the target page the pointer goes to.
Then use doc.set_toc(toc_list). All pesky detail is taken care of for you.
If the PDF already has a TOC, extract it to a list of that same structure via toc_list = doc.get_toc().
Then modify as required.

Python Flask image manipulation librery

I google it, but the number of library are overwhelming,
I'm looking for a image manipulation library, written in Python that I can implement in Flask;
I need to solve this simple sets of operations:
Upload the image.
Resize / scale the image (maintained the proportions).
Save the new image in a specific path with a specific name.
Remove the original image.
Also I notice that many promising project are unchanged in the last 2 years....

How can I update what is displayed in TextInput widget? python kivy

I have a TextInput widget that is suppose to display text within a .log file.
The python script looks like
logginfo = ObjectProperty()
with open('logtest.log', 'r') as file:
loginfo = file.read()
The kivy file looks like
TextInput:
id: logginfo
text: root.loginfo
The problem is, the log file is only read once and that is what is displayed.
How can I update loginfo whenever the .log file changes? In other words, how can I get a live feed of the logtest.log file?
You will have to produce a method/function that will check for changes and load the file to update the textbox for you. There is no "automagic" way to do it.
I don't work with kivy directly, but most GUI frameworks seem to come with some sort of timer, or timeout object. Kivy doesn't seem to be any different in this case. A quick search revealed that Kivy has a "Clock" object. I found some docs here.
Most of the time these work on a timeout, so you define the Clock, tell it what function to run, whether it should repeat or not, and how frequently to time out. Each time the Clock times out, the function will be called. You can code the function to do whatever you like, in this case, check the file for changes.
I'd suggest making a hash of the file (something simple like md5) and storing the hash in a variable. Then, each time the clock times out, it can simply compare the files hash, to the hash you stored in ram, and if it's changed, you know you need to update the text box with the new contents of the file. If it doesn't you don't need to re-access the file for another timeout interval.
If you have specific questions on problems you encounter trying to work through the project please make new questions with specific issues, again showing your code at that point.

Easily differentiate video files from image files in Node

I'm building a project where people can upload files, I would like to then display those files in a browser where people can interact with them (vote, comment etc)
However, this means I need to programatically build the html depending on the format of the video or image. Is there a way to feed a file (or filename) into a library, and determine whether I need to display it in a video element or an image element? Even a list of video formats vs image formats would help but I haven't seen anything in regards to that.
No module can reliably determine the file type. The user could either change the extension or even the magic number of the file to obfuscate it. The only reliable way it to try to pass file to some image / video transcoder to let it decide or error out if the format is invalid. This way you know you are working with known formats since all files are transcoded to your specific extensions. That could be mp4 or png. I recommend using handbrake for videos and sharp for images. Leaving the NPM links down below:
https://www.npmjs.com/package/handbrake-js
https://www.npmjs.com/package/sharp

node.js read images from PDF

I need to use PDF in a way similar to ZIP/RAR. To hold many images (ancient tibetan buddist literature), ideally 60000. But splitting in 10-100 volumes is OK.
Anything can be used for packing, but for unpacking we need Node.js. Because same PDF file must be served on web. But some users will need to use whole PDF.
So the question is, what node module I can use to read any single arbitrary image from huge PDF? Example would really help.
Every image is a single page. (Or in otherwords every page is single image)
We have been using https://github.com/mirkokiefer/Node-Magick for this....
But the pngs we get out sometimes are fairly low quality..

Resources