I am trying to play mp3 file using pyglet module.
Following some suggestions, I have already installed avbin64 and moved avbin64.dll to the directory where my python code is. but still, I am getting 2 errors
import pyglet
music = pyglet.resource.media('song.mp3')
music.play()
pyglet.app.run()
error code
Traceback (most recent call last):
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 59, in __init__
self._wave = wave.open(file)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 510, in open
return Wave_read(f)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 164, in __init__
self.initfp(f)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 131, in initfp
raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:/PycharmProjects/test/test2.py", line 3, in <module>
music = pyglet.resource.media('song.mp3')
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\resource.py", line 678, in media
return media.load(path, streaming=streaming)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\__init__.py", line 143, in load
raise first_exception
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\__init__.py", line 133, in load
loaded_source = decoder.decode(file, filename, streaming)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 109, in decode
return WaveSource(filename, file)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 61, in __init__
raise WAVEDecodeException(e)
pyglet.media.codecs.wave.WAVEDecodeException: file does not start with RIFF id
As per "Loading media", you're supposed to open audio (and video) files with pyglet.media.load:
music = pyglet.media.load('song.mp3')
You must also have ffmpeg installed for pyglet to be able to read mp3 files (as per Supported media types). Make sure to follow the installation instructions.
Related
This is just simple Python code that worked when I first ran it, but didn't work the next day, even though I didn't change anything:
from pytube import YouTube
link = "https://www.youtube.com/watch?v=6_ardA6TuX0"
video = YouTube(link)
yt = video.streams.get_highest_resolution()
yt.download("Lieder")
I get this Error:
Traceback (most recent call last):
File "C:\Users\edonj\OneDrive\Desktop\Spot\main.py", line 9, in <module>
yt.download("Lieder")
File "C:\Users\edonj\OneDrive\Desktop\Spot\venv\lib\site-packages\pytube\streams.py", line 252, in download
for chunk in request.stream(
File "C:\Users\edonj\OneDrive\Desktop\Spot\venv\lib\site-packages\pytube\request.py", line 185, in stream
chunk = response.read()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 476, in read
s = self._safe_read(self.length)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 628, in _safe_read
raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(66612 bytes read, 9370572 more expected)
VideoUnavailable.
Proxy will help you.
I have installed librosa correctly with pip3 on ubuntu subsystem on windows, but when I try to execute a simple program like this one:
import librosa
data, sr = librosa.load('sound.mp3')
print(data.shape)
It is what happens:
/home/henistein/librosa/librosa/core/audio.py:144: UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn('PySoundFile failed. Trying audioread instead.')
Traceback (most recent call last):
File "/home/henistein/librosa/librosa/core/audio.py", line 128, in load
with sf.SoundFile(path) as sf_desc:
File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 740, in __init__
self._file = self._open(file, mode_int, closefd)
File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 1264, in _open
_error_check(_snd.sf_error(file_ptr),
File "/home/henistein/.local/lib/python3.8/site-packages/soundfile.py", line 1455, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'sound.mp3': File contains data in an unknown format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PerfectPitch.py", line 2, in <module>
data, sr = librosa.load('sound.mp3')
File "/home/henistein/librosa/librosa/core/audio.py", line 145, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "/home/henistein/librosa/librosa/core/audio.py", line 169, in __audioread_load
with audioread.audio_open(path) as input_file:
File "/home/henistein/.local/lib/python3.8/site-packages/audioread/__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
What am I doing wrong?
According to the manual you'll probably also need to install ffmpeg, to allow for librosa to decode various formats.
Since you're working in the Ubuntu subsystem, simply
apt install ffmpeg
should do the trick.
Env:
Ubuntu 18.04
Python 3.6.6
pyglet 1.3.2
Issue:
Based on documentation of pyglet I try to run following code:
import pyglet
pyglet.options["audio"] = ("openal", "pulse", "directsound", "silent")
explosion = pyglet.media.load('explosion.wav')
But following exceptions occured:
1) if file was converted by ffmpeg -i input.mp3 output.wav
Traceback (most recent call last):
File "<path_to_dir>/test_sound.py", line 3, in <module>
explosion = pyglet.media.load('zxc.wav', streaming=False)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/loader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/loader.py", line 84, in load
return WaveSource(filename, file)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/riff.py", line 197, in __init__
raise WAVEFormatException('Not a WAVE file')
pyglet.media.sources.riff.WAVEFormatException: Not a WAVE file
2) or this for several .wav from internet
Traceback (most recent call last):
File "<path_to_dir>//test_sound.py", line 3, in <module>
explosion = pyglet.media.load('explosion.wav', streaming=False)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/loader.py", line 63, in load
source = get_source_loader().load(filename, file)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/loader.py", line 84, in load
return WaveSource(filename, file)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/riff.py", line 192, in __init__
format = wave_form.get_format_chunk()
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/riff.py", line 172, in get_format_chunk
for chunk in self.get_chunks():
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/riff.py", line 108, in get_chunks
chunk = cls(self.file, name, length, offset)
File "<path_to_env>lib/python3.6/site-packages/pyglet/media/sources/riff.py", line 153, in __init__
raise RIFFFormatException('Size of format chunk is incorrect.')
pyglet.media.sources.riff.RIFFFormatException: Size of format chunk is incorrect.
Question:
How to run .wav files via pyglet correctly?
Like in the example, it is probably either an issue with openal or the wav-files. Are the procedural sounds playing correctly, e.g.:
from pyglet.media.sources.procedural import Sine
sine = Sine(duration=1, frequency=500,
sample_size=16, sample_rate=44100)
pyglet.media.StaticSource(sine).play()
and can you share an offending wav-file? I just ran a test on Linux Mint 19, Python 3.7.1 and pyglet 1.3.2 with https://github.com/pyreiz/pyreiz/blob/master/reiz/media/wav/ding.wav and it runs fine.
Whenever I try to run my Rasa app using the run button in PyCharm, or try to use the debugger, I get the following error:
Traceback (most recent call last):
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/pykwalify/core.py", line 76, in __init__
self.source = yaml.load(stream)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/main.py", line 933, in load
loader = Loader(stream, version, preserve_quotes=preserve_quotes)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/loader.py", line 50, in __init__
Reader.__init__(self, stream, loader=self)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/reader.py", line 85, in __init__
self.stream = stream # type: Any # as .read is called
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/reader.py", line 130, in stream
self.determine_encoding()
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/reader.py", line 190, in determine_encoding
self.update_raw()
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/ruamel/yaml/reader.py", line 297, in update_raw
data = self.stream.read(size)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 473: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/matthewspeck/project/trainer_app/app.py", line 25, in <module>
parser=False, core=True)
File "/Users/matthewspeck/project/trainer_app/rasa_model.py", line 165, in make_rasa_model
rasa_config=rasa_config
File "/Users/matthewspeck/project/trainer_app/rasa_model.py", line 66, in __init__
self._parser = create_agent(use_rasa_nlu=True, load_models=True)
File "/Users/matthewspeck/project/trainer_app/rasa.py", line 32, in create_agent
domain = create_domain()
File "/Users/matthewspeck/project/trainer_app/rasa.py", line 83, in create_domain
domain = ClarifyDomain.load(domain_path)
File "/Users/project/clarification/domain.py", line 39, in load
domain = TemplateDomain.load(filename)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/rasa_core/domain.py", line 404, in load
cls.validate_domain_yaml(filename)
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/rasa_core/domain.py", line 438, in validate_domain_yaml
schema_files=[schema_file])
File "/Users/matthewspeck/anaconda3/envs/proj_env/lib/python3.6/site-packages/pykwalify/core.py", line 78, in __init__
raise CoreError(u"Unable to load any data from source yaml file")
pykwalify.errors.CoreError: <CoreError: error code 3: Unable to load any data from source yaml file: Path: '/'>
Process finished with exit code 1
However, when I run the app from my terminal, or from my text editor (I use VSCode), It runs with no problems whatsoever. I've looked online and every answer I see has something to do with Rasa, but nothing mentions problems with PyCharm.
I've also checked that the yaml for the domain is properly formatted, and it is. Anyone have any idea why I would be getting this error in PyCharm, but not in any other environment, and how I could fix it?
I believe your problem was fixed with Rasa version 0.12 ([changelog][1]): https://github.com/RasaHQ/rasa_core/blob/master/CHANGELOG.rst#0120---2018-11-11 .
I recommend upgrading to a newer version of Rasa Core which parses the training data correctly.
I am trying to use the SpeechRecognition library (https://pypi.python.org/pypi/SpeechRecognition/). When running the example code (full example) below:
#!/usr/bin/env python3
import speech_recognition as sr
# obtain path to "english.wav" in the same folder as this script
from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav")
#AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
#AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")
# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source) # read the entire audio file
I receive this error:
/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/adamg/te/Polli/ASR/SpeechRecognitionTest0.py
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 174, in __enter__
self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 497, in open
return Wave_read(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 163, in __init__
self.initfp(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wave.py", line 130, in initfp
raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 179, in __enter__
self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 887, in open
return Aifc_read(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 340, in __init__
self.initfp(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 305, in initfp
raise Error('file does not start with FORM id')
aifc.Error: file does not start with FORM id
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/adamg/te/Polli/ASR/SpeechRecognitionTest0.py", line 13, in <module>
with sr.AudioFile(AUDIO_FILE) as source:
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/speech_recognition/__init__.py", line 199, in __enter__
self.audio_reader = aifc.open(aiff_file, "rb")
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 887, in open
return Aifc_read(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 340, in __init__
self.initfp(f)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/aifc.py", line 303, in initfp
chunk = Chunk(file)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/chunk.py", line 63, in __init__
raise EOFError
EOFError
Process finished with exit code 1
How can this be fixed?
I had the same problem for a while, my mistake is to download the wav file using "save as". When I double click to play the wav file, I am not able to play the wav file using any player. After cloning or downloading the entire zip file, I am able to play the wav file and the error disappears.
Your wav file is probably corrupted. To check try to play the file using any media player if possible. Download the audio file into your environment correctly and then it should work.
I have faced this issue when I did a mistake by downloading the file the incorrect way, I downloaded the audio file using the following command in the google colab:
[!wget 'https://github.com/mozilla/DeepSpeech/blob/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']
This threw an error as the audio file was corrupted(could not be played my media player when downloaded).
I was able to correct the issue by downloading the following way:
[!wget 'https://raw.githubusercontent.com/mozilla/DeepSpeech/master/data/smoke_test/LDC93S1_pcms16le_1_16000.wav']
For what it's worth, I ran into this problem when git LFS WAV files I had stored in a repo were not cloned properly. Their pointers were present, but the files were not. A
git lfs pull
fixed the problem.
That being said, this might just happen any time you a file is pointed to that isn't actually an audio file that is "complete". Hopefully that helps!