Im trying to create a virtual assistant but I cant get the gTTS working (google text to speech) working and I cant seem to fix it
import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS
def speak(text):
tts = gTTS(text = text, lang="en")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
speak("hello i am bob")
This is the error im getting
File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 13, in <module>
speak("hello i am bob")
File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 10, in speak
tts.save(filename)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 295, in save
self.write_to_fp(f)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 251, in write_to_fp
prepared_requests = self._prepare_requests()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 194, in _prepare_requests
part_tk = self.token.calculate_token(part)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
seed = self._get_token_key()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 58, in _get_token_key
raise ValueError(
ValueError: Unable to find token seed! Did https://translate.google.com change?
I had the same error, until I upgrade gTTS-token
pip install gTTS-token --upgrade
And let me tell you as well that I have a Windows machine in which I run a Linux terminal. In that case I couldn't make it work (Nevertheless try it if this is your case).
Hope it works!
There was an ISSUE with gtts depending on the version you were using that returned this token seed error.
The ISSUE has been closed and it seems updating go gtts version 2.1.2 and newest resolved the problem.
Obs: I personally used 2.2.1 today and everything worked as expected.
I had the same problem on Windows.
I've just uninstalled the module gtts and installed it again(now having the last version of it)
Related
Traceback (most recent call last):
File "g:\mydrive\ \pdftotext_pdfminer.py", line 3, in <module>
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\pdfinterp.py", line 7, in <module>
from .cmapdb import CMap
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\encodingdb.py", line 7, in <module>
from .psparser import PSLiteral
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\psparser.py", line 22, in <module>
from .utils import choplist
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\utils.py", line 31, in <module>
import charset_normalizer # For str encoding detection
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\api.py", line 10, in <module>
from charset_normalizer.md import mess_ratio
File "charset_normalizer\md.py", line 5, in <module>
ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\constant.py)
This error happens whenever I'm using pdfminer. I also installed pdfminer-six
My code worked just fine until two days ago.
It started to happen today when I tried to just run it again without any adjustment in the file
I'm assuming maybe it's the pdfminer's problem but there's no update about the module...
(I'm running this on my conda env)
Does anyone know what this error means? and how to fix it?
When I encountered this I used:
pip install chardet
there. I faced the same problem when trying to use the pdfplumber package today (2022-11-24) from a script I have long used with no problem. I don't know why this error is happening but found one of the solutions in this link helpful:
How to fix AttributeError: partially initialized module?
Briefly, I removed my entire virtual environment using the command conda env remove --name ds (being ds the name of my environment). Then, I created a new one and installed every package I needed again through conda or pip. It is working perfectly now. Hope it works for you as well.
Out of curiosity, I have installed Tensorflow last week. Maybe it interfered with pdfplumber somehow (not sure). Have you installed any new package since the last time you used pdfminer? Best of luck!
use follow instead.
pip install mmcv-full==1.3.17
from playsound import playsound
playsound("1.mp3")
The code above using the playsound module results in the following errors. How to resolve?
Error 259 for command:
play 1.mp3 wait
The driver cannot recognize the specified command parameter.
Error 263 for command:
close 1.mp3
The specified device is not open or is not recognized by MCI.
Failed to close the file: 1.mp3
Traceback (most recent call last):
File "C:\Users\itsra\OneDrive\Desktop\Python\test.py", line 4, in <module>
playsound("1.mp3")
File "C:\Users\itsra\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\playsound.py", line 73, in _playsoundWin
winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
File "C:\Users\itsra\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\playsound.py", line 64, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 259 for command:
play 1.mp3 wait
The driver cannot recognize the specified command parameter.
I also got the same problem. Try downgrading playsound version.
Use
pip install playsound==1.2.2
This solved it.
I also faced a similar problem. Try converting into a wav file. It worked for me and I think the problem is because of the lack of information about the bit rate of the music in the file. enter image description here
This version of Pyaudio worked for me :
pip install playsound==1.2.2
Solution 1:
I got this error & downgraded to 1.2.2 (from 1.3.0) as suggested in other comments & it worked.
Solution 2:
The other solution that I tried (v 1.3.0) is to rename the file & it worked.
I get the error if file name = "lost_money.mp3" or "money_lost.mp3"
But not: "lost money.mp3" or "transaction_failed.mp3" or "made_profit.mp3"
playsound library is simple to use but it does not support some audio formats. This solution works for all type of formats
from mutagen.mp3 import MP3
import time
import miniaudio
file='1.mp3'
audio = MP3(file)
length=audio.info.length
stream = miniaudio.stream_file(file)
with miniaudio.PlaybackDevice() as device:
device.start(stream)
print('playing')
time.sleep(length)
python app.py
Traceback (most recent call last):
File "app.py", line 1, in <module>
from chatbot import chatbot
File "C:\Users\hp\Desktop\try_projects\chat_bot\chatbot.py", line 1, in <module>
from chatterbot import ChatBot
ModuleNotFoundError: No module named 'chatterbot'
Code is
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer, ChatterBotCorpusTrainer
chatbot= ChatBot('Crazy')
what might be the solution to this problem?
python version: 3.8.3
Try installing the previous version of ChatterBot.
pip install chatterbot==1.0.4
This should work, unless there are some other problems. I had the same problem and it worked for me.
There would be another problem if you are using Python 3.8.x . In Python 3.8.x, a few functions of a few modules were removed.
You will be able to import ChattberBot , but when you name the bot, there will be an error.
File "C:\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
Copy the location for the file given in the last line, where the error occurs.
C:\Python38\lib\site-packages\sqlalchemy\util\compat.py
Open file with IDLE or whatever editor you have. Please do Not open the file directly(this will run the file, and you will not be able to see the code) , instead Open with IDLE or Your Text editor
Then , go to line 264 in that . It would be written
time_func = time.clock
Instead of this change it to
time_func = time.perf_counter()
I Hope this helped! This was my first answer on StackOverflow !
import librosa
import librosa.display
import IPython.display
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.font_manager as fm
audio_path = 'rec.wav'
y, sr = librosa.load(audio_path)
I tried to load the audio file into librosa.
So I wrote the code like that.
But I get the error "File contains data in an unknown format", "File contains data in an unknown format".
I searched on Google and I was told to install ffmpeg.
So I installed ffmpeg but still get the error
What's wrong?
(I guess there is a problem with the encoding.........)
all error messege:
Traceback (most recent call last):
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 129, in load
with sf.SoundFile(path) as sf_desc:
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 629, in __init__
self._file = self._open(file, mode_int, closefd)
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1184, in _open
"Error opening {0!r}: ".format(self.name))
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1357, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'rec.mp3': File contains data in an unknown format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/****/PycharmProjects/pitch_project_/pitdetec.py", line 12, in <module>
y, sr = librosa.load(audio_path)
File "C:\Users\*****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 147, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 171, in __audioread_load
with audioread.audio_open(path) as input_file:
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
try:
audio_path = 'C:/Users/ddolcju/PycharmProjects/pitch_project/rec.mp3'
There are few things you need to check:
librosa can't read mp3 files directly so it tries to use the audioread package.
Audioread tries to utilise a number of different packages that may or may not be installed. One of those is ffmpeg.
However it uses FFmpeg 'via its command-line interface'. I think this is the reason that pip installing FFmpeg doesn't work. It needs the ffmpeg.exe file.
You can download the ffmpeg installer from here
After it is installed make sure you can start ffmpeg from the command line (type ffmpeg -h). You will probably need to add the path to the install folder (eg c:\ffmpeg\bin) to the Windows path.
Finally, make sure to restart your IDE. Visual Studio Code probably won't recognise the new path until after a reset.
In ubuntu I resolved it by following command
sudo apt update
sudo apt install ffmpeg
pip install ffmpeg did not worked for me
I got the same problem on windows 10, after installing ffmpeg and configuring it to PATH, it works. Need restart a python session.
I'm assuming that you solved your problem, but if anyone else has this problem:
I installed ffmpeg (the following code) and it worked.
pip install ffmpeg
wav files should be supported natively, according to https://github.com/librosa/librosa/issues/219
mp3 on the other hand requires a backend, e.g. ffmpeg
I cannot get plyer.tts to work on Windows.
Installed:
plyer 1.3.0
python 3.6.5
Example:
>>> from plyer import tts
>>> tts.speak("Hello world!")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\plyer\facades\tts.py", line 30, in speak
self._speak(message=message)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\plyer\facades\tts.py", line 35, in _speak
raise NotImplementedError()
NotImplementedError
The documentation states that tts works on Windows and I remember getting it to work in the past on a different PC.
What could be the problem?
I had the same issue with a NotImplementedError() . It means that the text-to-speech engine/software that it's looking for is not being found on the machine. Although plyer worked for me with the native tts on Mac OS X, on Windows you have to download tts software, as I guess plyer isn't set up to find the native one anymore, or it's not named the same as it used to be, if you say it worked in the past.
Fix it by downloading espeak from http://espeak.sourceforge.net. Install it and move the espeak.exe file somewhere python can find it. For me, the easiest thing was to move it to the top-level folder of the script I was trying to run.