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.
Related
Good day. I used to have a normally working code which exports styled dataframe as a PNG. For some reason now it doesn't work except for certain machines used by my fellow coworkers. I suspect iit is somehow relevant to the latest windows or Chrome updates but I am not sure.
Sample code:
import numpy as np
import pandas as pd
import dataframe_image as dfi
my_array = np.array([[11,22,33],[44,55,66]])
df = pd.DataFrame(my_array, columns = ['Column_A','Column_B','Column_C'])
df=df.style.set_properties(**{'background-color': 'black',
'color': 'white'})
display(df)
dfi.export(df, 'Test.png', table_conversion='chrome')
Received error:
Traceback (most recent call last):
File "C:\Users\Anato\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 13, in
dfi.export(df, 'Test.png', table_conversion='chrome')
File "C:\Users\Anato\anaconda3\lib\site-packages\dataframe_image_pandas_accessor.py", line 24, in export
dpi=None
File "C:\Users\Anato\anaconda3\lib\site-packages\dataframe_image_pandas_accessor.py", line 73, in _export
File "C:\Users\Anato\anaconda3\lib\site-packages\dataframe_image_screenshot.py", line 167, in run
max_crop = int(img.shape[1] * 0.15)
File "", line 40, in take_screenshot_override
img = mimage.imread(buffer)
File "C:\Users\Anato\anaconda3\lib\site-packages\matplotlib\image.py", line 1541, in imread
with img_open(fname) as image:
File "C:\Users\Anato\anaconda3\lib\site-packages\PIL\ImageFile.py", line 121, in init
self._open()
File "C:\Users\Anato\anaconda3\lib\site-packages\PIL\PngImagePlugin.py", line 677, in _open
raise SyntaxError("not a PNG file")
File "", line unknown
SyntaxError: not a PNG file
Searched the web and found no answer that could help. Tried udating packages and python itself. I believe it has to do with latest system updates but found no solution for over a week.
In my case the following worked:
Update windows to the latest version
Update conda
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 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.
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!
I have the virtualbox 5.0.10 Python sdk in my source root, but when I run my code the program will fail:
Traceback (most recent call last):
File "C:/Users/xiao/.PyCharm50/config/scratches/scratch", line 2, in <module>
mgr=vboxapi.VirtualBoxManager()
File "C:\Users\xiao\Desktop\test\vboxapi\__init__.py", line 1018, in __init__
self.platform = PlatformMSCOM(dPlatformParams)
File "C:\Users\xiao\Desktop\test\vboxapi\__init__.py", line 513, in __init__
win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
File "C:\Python27\lib\site-packages\win32com\client\gencache.py", line 540, in EnsureDispatch
disp_class = CLSIDToClass.GetClass(str(disp_clsid))
File "C:\Python27\lib\site-packages\win32com\client\CLSIDToClass.py", line 46, in GetClass
return mapCLSIDToClass[clsid]
KeyError: '{7844AA05-B02E-4CDD-A04F-ADE4A762E6B7}'
Here is my code: (really simple, right?)
import vboxapi
mgr=vboxapi.VirtualBoxManager()
This program is buggy under Python 2.7.6, but runabble under Python 3.4.0.
Why? How can I fix that?