How can I fix this gTTS issue? - python-3.x

I have the following code with gTTS
from gtts import gTTS
obj = gTTS(text = "Hello there", lang = 'en')
obj.save("hello.mp3")
For some reason, however, (I'm using version 2.2.3, python 3.7.3) it was working just fine
a few days ago on my raspberry pi 4 Model B and it suddenly stopped again.
I fixed it before by upgrading to a newer version (2.2.3 in my case), but
it worked for a few months and now I'm having the same issue with it as before -
when saving the mp3 file it takes too much time, whereas when it was working fine it took no more than a second (now it needs at least a minute or more), before you say it, it is not due to my internet connection. I've tried everything on the internet and I can't seem to find a solution that works 100% forever, on windows it works just fine and the mp3 file is saved instantly (same gTTS version), but on rpi it takes too much time when it should take no more than a second (and it worked that way until it magically stopped a few days ago).

Related

Tkvideo is working on one file but not an exact copy

Alright, guys, I'm in need of some serious help here. I am running python3 on a mac, using a virtual environment in vs code. So to the point, I have a python project where I am opening a window and playing a video on loop here is the code
from tkinter import *
import numpy
from tkvideo import tkvideo
from PIL import Image, ImageTk
import os
root = Tk()
my_label = Label(root)
root.geometry("500x500")
root.configure(bg='black')
root.resizable(False, False)
my_label.pack()
my_label.config(borderwidth=0)
player = tkvideo("path/test.mp4", my_label, loop = 1, size = (600,338))
# root.iconbitmap('path/Logo.png')
root.title('Elvis')
ico = Image.open('Logo.png')
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(False, photo)
player.play()
root.mainloop()
it works fine and runs with no issues, the problem comes in at my other python project.
I have everything the exact same but with different file locations.It does run but the video doesn't play, the UI looks different, and the logo is replaced with a standard python logo. If you were wondering yes, I do have all the same packages installed and have even tried uninstalling and reinstalling the packages. anyways this is the error RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable. i am new to python but i have a pretty good grasp on how it works. I just don't see how it would work on one but not on another identical one with the same packages. If anyone more advanced than me could help it would be greatly appreciated. I am sorry if there is a super obvious answer to this. I have worked for a good 4 hours and can't seem to figure it out. anyways ---thank you

Webscraping with selenium, click() line only works after x number of tries

Hi I have a script that scrapes a website based on filters, this was working fine up until the latest chrome update and chromedriver update and then one of the filters was failing to click.
I have a try and except loop that repeats for 10 tries, sometimes this is enough sometimes and other times I need > 15 clicks of the same line of code for it to eventually work.
Here is my code to initiate the webpage:
from selenium import webdriver
url='https://www.marketscreener.com/stock-exchange/calendar/finance/'
options=webdriver.ChromeOptions()
chrome_prefs = {}
options.experimental_options["prefs"]=chrome_prefs
chrome_prefs["profile.defaul_content_settings"] = {"popups":1}
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-notifications')
driver = webdriver.Chrome(executable_path=r'foo.exe',options=options)
after I log in using my credentials I try this line of code:
driver.find_element_by_id("selCountry").click()
which opens up the country filter drop down menu. The majority of times it takes an arbitrary number >10 tries for it to eventually work.
I am using chrome version 87.0.4280.141 and its chromedriver with python 3.7.
Can anyone provide a better solution to my problem or maybe an explanation on why it suceedes after x number of tries?

Python Sounddevice Callback returning an array with zeros

I am trying the Python Sounddevice lib to stream audio from the microphone
self.audio_streamer = sd.Stream(device=self.input_device, channels=self.channels,
samplerate=self.sampling_rate, dtype='int16',
callback=self.update_audio_feed, blocksize=self.audio_block_size,
latency='low')```
def update_audio_feed(self, indata, outdata, frames, time, status):
print("update_audio_feed")
if status:
print(status, file=sys.stderr)
print(indata)
outdata.fill(0)
Output :
The indata is an array with 0's always from the callback.
update_audio_feed
[[0]
[0]
[0]
...
[0]
[0]
[0]]
Sounddevice is detectingt the mic fine but not getting the signal :
Device Info: {'name': 'MacBook Pro Microphone', 'hostapi': 0, 'max_input_channels': 1, 'max_output_channels': 0, 'default_low_input_latency': 0.04852607709750567, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.05868480725623583, 'default_high_output_latency': 0.1, 'default_samplerate': 44100.0}
Sampling rate: 44100.0
The issue on my mac was a security/ permissions issue . When I tried running the python script through Visual Studio Console it did not work... But when I tried the mac Terminal it prompted for the microphone and everything started to work..
More details here :
https://www.reddit.com/r/MacOS/comments/9lwyz0/mojave_not_privacy_settings_blocking_all_mic/
https://github.com/spatialaudio/python-sounddevice/issues/267
I've been using sounddevice without major issues on a number of Macs for a few months now.
Firstly, have you tried the wire.py example? That works out of the box for me.
Two things that I noticed in your code:
I haven't tried specifying the blocksize. I have only used the default value of 0. I could well believe that may be causing you issues.
You've specified a "low" latency Stream. At the very least on OSX10.13 this produces very unstable audio (lots of input underflows). If stable audio is important to you, I would recommend you consider latency options higher than "high". For reference, Audacity uses 100ms and obtains stable audio. Also, input underflows often mean indata is filled with zeros.
For those interested in this problem in the future, you may wish to look at the issue posted on sounddevice at GitHub.
I had the same issue on MacOS, but I was running the script from vscode. Actually vscode wouldn't ask for microphone permission, so it will assume it has this permission (which it didn't) and you will get an empty array.
Switched to running the script from terminal and everything changed, I got a permission request and everything went well.

Adapting Selenium Script for Raspberry Pi

Preface: I have very limited experience with linux and selenium in general. Also this is a multipart question.
Hi there,
I've written a script that I want to run on my Raspberry Pi model 3B which is running Raspbian OS.
I originally built it on a Windows machine (pretty stupid mistake to build it for the wrong platform but anyway) and now need to adapt it so it runs on the Pi.
The main thing I am concerned about is the usage of selenium and chromedriver. I have downloaded chromium-chromedriver (chromium-chromedriver 34.0.1847.116-0ubuntu2 in armhf (Release)) from this repository.
First Question
The file downloads as a .deb which I have never seen before. It opts to install, however I have no idea where it installs as it does not give the option to install to a different directory. I've tried search for it with find, but nothing comes up. Where does it go by default in Raspbian OS?
Second Question
I know I will have to change some expressions because I am using chromium-chromedriver instead of chrome driver, but I am unsure which ones as I don't know selenium that well. This is the main instance here. Do I just change all instances of "Chrome" including "chrome_options" to "Chromium/chromium_options"?
from selenium.webdriver import Chrome
from contextlib import closing
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
#Scrape out the table information
with closing(Chrome(chrome_options=chrome_options)) as driver:
Lastly, for the purpose of finding the process with psutil and ending it with process.kill(), the text ID of the driver in task manager should just be chromium-chromedriver.exe right?
Any and all help and advice appreciated.
Thank you all for your time.
L

TinyTag import error python 3.3

I have been trying to import tinytag into python to be able to read mp3 tags but I keep receiving the same error. This is the code I am running
from tinytag import TinyTag
tag = TinyTag.get('/some/music.mp3)
print(tag.album)
and the error I recieve from this is
ImportError: No module named 'tinytag'
If anyone could give me any information on how to fix this would be greatly appreciated or can suggest another reader to use that is compatible with python 3.
Like you, I'm new to Python and I struggled with this but I worked it out eventually. I'm sure there is better way, but this worked (on windows, with my examples)
I installed a python module called easy_install (bundled with
setuptools). you can Google this. In the directory \Python26\Scripts you should see an exe file called easy_install if this has worked
Then I downloaded TinyTag to my pc eg
\downloads\tinytag-0.6.1.tar.gz
Then in note pad I wrote a small text file called myinstall.bat with
the contents
easy_install C:/downloads/tinytag-0.6.1.tar.gz
pause
then saved it into \Python26\Scripts and ran it (the pause keeps the
window open so you can see it worked)
Subsequently I started using some software called JetBrains to code with (it's commercial but there is a free edition) and that has an install tool built in which is even easier) I hope this helps

Resources