I am doing Ai research. I have been using pyttsx3 for the voice. The pyttsx3 function does not produce visemes. It does produce limited timing for each word. I intend to make a function that take in the text, then produce the visemes for animation of an avatar. The problem is that the data is trapped in the engine. I wanted to save the audio to a file, then load and extract it. The problem is that the save_to_file appears to be a dummy function. I have spent days researching it and the best that I have gotten are files with 0 (zero) bytes. What is going on?
I came across this when searching for solutions to the same problem.
Eventually, what I noticed was that it was to do with the file name. When I chose the file name to be 'test.mp3' or 'name.mp3', it saved properly, but if I changed the name to 'text.mp3' or basically anything else while keeping everything else exactly the same, it produced a file of zero bytes in size.
When I saved it to a different folder but the same name, e.g. 'folder/test.mp3', then it also failed, presumably because it's the full absolute path name which matters.
My hack/workaround was to just always use the file name 'test.mp3' in the same directory, and then use python's os module to move it or change the name immediately afterwards, e.g.:
engine.save_to_file(text, "test.mp3")
os.rename("test.mp3", "folder/nameIwanttogive.mp3")
So 'test.mp3' seemed to work for me. Maybe see what works by initially copying and pasting some demo code from a website.
I had the same problem, it was because i forgot a litle thing:
engine.save_to_file('hello', 'test.mp3')
it just for preparation, to implement everything use the code:
import pyttsx3 as tts
engine=tts.init()
engine.save_to_file('hello', 'HelloSound.mp3')
engine.runAndWait() # implement everything
I just update my pyttsx3 to 2.90 and started to work!! Just reinstall!
try:
pip uninstall pyttsx3
and than:
pip install pyttsx3
Related
I have a project in mind, but there is a section that I don't know how to do. I'm using Python version 3.6 and windows 10. For example we have a file name of "example.txt" I want to prevent the name and its content of this file from being changed.
I did research on this topic, but I could not reach any research. Can we prevent the file's name (including its extension) from changing or its contents?To realize this, I think it is necessary to start as an administrator.
Thanks.
It is possible to stop another program from editing a file by locking it in python.
There is a module that does this called filelock. Take a look at the source code to see how it is done.
It is also worth noting that more advanced ransomware will try to stop processes so they can encrypt files, so this might not work in all cases.
Qualifier quite new to Python.
I wrote some Python code importing pandas, selenium, sys, os, tkinter, and pillow, then put together with pyinstaller and NSIS.
The programme uses a csv file for its input and updates this based on user actions. The updates are to be saved internally so if the user quits they can continue where they left off.
It all saves properly, user progress saves and picks up correctly, and if I "download CSV" the file is up-to-date. It all works perfectly, functionally speaking.
However, when the programme is run, the csv that it starts with is not where it is saving the progress. It stays the same. The "progress" data is being saved somewhere else From a data security perspective, I need to know where it is saving. I could not find it after hours of looking.
Even if I uninstall the programme and reinstall, it still remembers the progress. Tested also on machines with no Python etc.
I am using:
if getattr(sys, 'frozen', False):
CurrentPath = sys._MEIPASS
else:
CurrentPath = os.path.dirname(__file__)
Could that be it?
The save line itself is rather standard:
df.to_csv('file_s.csv',encoding='utf-8', index=False)
My only other idea is it relates to NSIS installer and the uninstall script. There are painfully few tutorials for beginners on that. If the community thinks that is the issue, I think it best I post a new question with relevant info.
Apologies if this is too vague and happy to provide anymore needed info!
You are defining the CurrentPath variable using the standard "if frozen" approach, which looks OK. But, you don't then seem to use it when you save the file.
Try explicitly concatenating it with the filename to save
df.to_csv(os.path.join(CurrentPath,'file_s.csv'),encoding='utf-8', index=False)
Note that when you run as a executable, sys._MEIPASS will be a temporary folder created (on Windows atleast) somewhere like C:\Users\<you>\AppData\Local\Temp\MEIXXX
I'm trying to use playsound to play a file within the folder of my code, however every time I run my code it seems it is able to call the file however I always receive this output:
playsound.PlaysoundException:
Error 277 for command:
open "para.mp3" alias playsound_0.9208788744295284
A problem occurred in initializing MCI.
The code that is run is just the use of the playsound function:
from playsound import playsound
playsound("01. Humongous.mp3")
I'm unsure if this is just an issue with my machine or something that I'm missing?
Convert the mp3 file to wav. Worked for me.
Managed to fix it. After hours of ripping my hair out I eventually tried a different file to play and it worked. Not actually sure if there is a bitrate limit with the playsound library but it certainly didn't like that particular file. Tried another file with a lower bitrate and it worked fine.
I also faced the same issue it is not with the bit rate of the file, it seems to be the tags in the music file like "track title, cover art, album name, encoding" and so on is causing it so I would like to recommend you to remove these tags and leave it as such, to do this editing I used mp3tag application you can get it from here. This worked for me. You can check instructables to know how to use this application to edit tags.
If you want those tags you can type it out and check if again the problem arises if it does then don't add the tags.
Try removing the period from the filename you're playing and try again. I don't know what system you're running this on, but it might be interfering with the file reading process.
In playsound,for (.mp3)
you can't directly upload the customized mp3 file because of some issue in bit initailizaing.
To solve this issue,
We need to change our .mp3 file to .mp3 format again on some audio converter application or online converter. Now converted mp3 file can be flawlessly accessed for playsound.playsound(dir/users/converted/song.mp3).Enjoy it..
I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py
First of all, please excuse me if I'm using some of the terminology incorrectly (accountant by trade ...)
I'm writing a piece of code that I was planning to pack as .exe product.
I've already included number of standard libraries (xlrd, csv, math, operator, os, shutil, time, datetime, and xlwings). Unfortunately, when I've added 'dataextract' library my program stopped working.
dataextract is an API written specifically for software called Tableau (one of the leading BI solutions on the market). Also Tableau website says it does not provide any maintenance support for it at the moment.
I've tested it on very basic setup:
from xlwings import Workbook, Sheet, Range
Workbook.set_mock_caller(r'X:\JAC Reporting\Tables\Pawel\Development\_DevXL\Test1.xlsx')
f = Workbook.caller()
s = raw_input('Type in anything: ')
Range(1, (2, 1)).value = s
This works perfectly fine. After adding:
import dataextract as tde
The Console (black box) will only flash on the screen and nothing happens.
Questions:
Does library (in this case 'dataextract') has to meet certain criteria to be compatible with py2exe?
As Tableau does not maintain the original code, does it mean I won't be able to pack it into .exe using py2exe?
Finally: I'm using 'dataextract' for almost 2 years now and as long as you will run the program through .py file it works like a charm :) I just decided to take it one step further.
Any comments/input would be greatly appreciated.
EDIT:
Not sure does it help or not, but when I tried to run the same script using cx_Freeze compiler got below error:
First of all massive thanks to #Andris as he pointed me at the correct direction.
It turned out dataextrac library dlls are not automatically copied while compiler is running. Therefore you need to copy them from 'site-package/dataextrac/bin' into 'dist' folder.
Also from 12 dlls you only need 9 of them (I tried running exe file for each of them). One you don't need are: icin44.dll, msvcp100.dll and msvcr100.dll.
To be on the safe side I will be coping them anyway though.
Hope this post will be any help to otheres :)