How to close the .mp3 file in Text to Speech as show in the details? - text-to-speech

In the above code I am able to convert the text 'Hello world' in the speech but how to close the .mp3 that is created. os.remove will not work until that .mp3 file is closed.
Please suggest.
I am trying text to speech functionality
import os
from gtts import gTTS
myobj = gTTS(text='Hello world', lang="en", slow=False)
myobj.save("audio1.mp3")
os.startfile('audio1.mp3')
What I expect is audio1.mp3 should be closed.

Related

Extracting embedded PNG byte streams from PDF

I am programming in Python, but if some tool/library exists in another language that would help me considerably, I am open to suggestions.
I have a large collection of pdf pages that live in a database, and I am trying to automate the collection of those pages to build some image recognition models with them.
These "pdfs" are actually just PNG images encased with a PDF wrapper (presumably so they can be read by PDF readers like Adobe Acrobat). I need the pdfs in image format to feed into the image recognition model pipeline. I am assuming they are PNG images, because when I save the images from the browser (i.e., right click and save image as), the resulting file is a PNG file.
After reading this question from 2010, and checking out this blog post from 2007, I've concluded that there must be a way to just extract the PNG byte array from the PDF instead of re-converting the PDF into a new image. Oddly though, I couldn't find the PNG file header with
#Python 3.6
header = bytes([137, 80, 78, 71, 13, 10, 26, 10])
#the resulting header looks like this: b'\x89PNG\r\n\x1a\n'
file.find(header)
Does that mean that the embedded image is not in fact a PNG image?
If there is no easy way to extract the embedded image byte array, what tool might I use to automate the conversion of each PDF file to some image format (preferably JPEG, PNG, or TIFF)?
Edit: I know tools like ImageMagick exist for format conversions, but I'd really rather do the extraction method for the sake of learning more about these file formats.
pip install pdf2image
pip install pillow
pip install numpy
pip install opencv-python
Then,
import numpy as np
from pdf2image import convert_from_path as read
import PIL
import cv2
#pdf in the form of numpy array to play around with in OpenCV or PIL
img = np.asarray(read('path to the pdf file')[0])#first page of pdf
cv2.imwrite('path to save the image with the file extension',img)

Google Colaboratory Export Data Frame

Im using google colaboratory to run some models. I was able to upload a csv file with features in google drive, import it in and run models on that data. I want to export the final dataframe out to csv. Cant find a way to do that, please advise.
df.to_csv('df.csv', index=False)
This runs without an error, but I cant find where the file is saved.
Or let me know if there is a better way to export my df out.
You can download the data back to your local machine with
from google.colab import files
files.download('df.csv')
You can find answer here:
Exporting Data from google colab to local machine
So what you need to do is:
- open the left pane
- select 'Files' tab
- click 'Refresh'
- right click the file, then download

Can I use blender to add subtitle to a video?

I want to use Blender to add a subtitle for my video(NOTE:IT IS A .SRT or .ASS FILE but not add a text),but I can not find the button.How to do it?
While blender recently got a feature to export srt files from text strips added in the VSE, it does not support muxing an srt file into a video. It also does not have a feature to import or display srt text within the VSE.

Export Core-Plot to CSV / Excel - iOS

I've been asked to extend an app I've built to include the ability to export a graph, which is created using Core-Plot, for use in Excel.
Is there currently anyway to do this? Or is the 'only' way to export the data for the graph as a CSV file which the user then turns into the graph?
My current idea was to get the user to email the CSV file using the iPad/iPhone in built mail API..
Cheers.

VBA Export embedded video from Powerpoint presentation

I'm trying to convert an entire presentation to HTML, extracting all the embedded content etc along the way. I've got text, audio, narrations etc all working fine but am having trouble finding out how to export video content.
Im looping through all slides in the presentation, then all shapes on the slide, looking for shapes of type msoMedia. If I find one, then I check it's MediaType. If it's ppMediaTypeMovie, then I can find the source file of an externally linked video file using Shape.LinkFormat.SourceFullName, but I can't for the life of me find out how to access EMBEDDED content.
If I find a shape with a MediaType of ppMediaTypeSound then I can use Shape.SoundFormat.Export to export the audio. Does anybody know of an equivalent for VIDEO shapes? (There's no Shape.VideoFormat) I've spent days looking through every possible data member I can but to no avail.
It appears Microsoft extract the contents of the media file to a temporary folder anyway, and embedded videos still provide a LinkFormat.SourceFullName to the extracted video:
?oshape.LinkFormat.SourceFullName
C:\Users\Alex\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO\F26FF1D0.m4v
All that I need to do is fire this file through ffmpeg and I've got my video, in the format I want!
Thanks for your help :)
Note: You may find that the .Export method doesn't work for embedded sounds either in recent PPT versions.
Alex's suggestion is what I'd look into first; otherwise you can unzip the PPTX/PPSX/etc and find the videos in the media folder. Or you might try saving as an XML presentation; you might be able to parse the video out of that.