Can't get librosa load a wav file - python

I got an audio dataset of many wav files and tired to use librosa to edit, but I have trouble reading some certain files by using librosa.load.Could someone help me figure it out?
here is my code:
import librosa
sound_clip = librosa.load('audio/fold1/180937-7-3-10.wav')
print(sound_clip)
here is the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-93fe2f032e98> in <module>()
----> 1 sound_clip = librosa.load('audio/fold1/180937-7-3-10.wav')
2 print(sound_clip)
/home/uri7910/anaconda2/envs/tensorflow011/lib/python2.7/site-packages/librosa/core/audio.pyc in load(path, sr, mono, offset, duration, dtype)
107
108 y = []
--> 109 with audioread.audio_open(os.path.realpath(path)) as input_file:
110 sr_native = input_file.samplerate
111 n_channels = input_file.channels
/home/uri7910/anaconda2/envs/tensorflow011/lib/python2.7/site-packages/audioread/__init__.pyc in audio_open(path)
100 from . import maddec
101 try:
--> 102 return maddec.MadAudioFile(path)
103 except DecodeError:
104 pass
/home/uri7910/anaconda2/envs/tensorflow011/lib/python2.7/site-packages/audioread/maddec.pyc in __init__(self, filename)
24 def __init__(self, filename):
25 self.fp = open(filename, 'rb')
---> 26 self.mf = mad.MadFile(self.fp)
27 if not self.mf.total_time(): # Indicates a failed open.
28 raise UnsupportedError()
AttributeError: 'module' object has no attribute 'MadFile'

The failing line is:
self.mf = mad.MadFile(self.fp)
AttributeError: 'module' object has no attribute 'MadFile'
This looks to be a problem with the pyMad library. Would suggest looking into upgrading or reinstalling. that library. If that fails you might want to raise a bug.

Related

Error in importing shapefile in jupyter using geopanda

I am using Jupyter from Anaconda and trying to import a shapefile with following command line:
import geopandas as gpd
gdf = gpd.read_file('C:\Downloads\Temp\shapefile\regions.shp')
print (gdf)
gdf.plot()
However, I got following errors:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 gdf = gpd.read_file('C:\Downloads\Temp\shapefile\regions.shp')
2 print (gdf)
3 gdf.plot()
File C:\Anaconda3\lib\site-packages\geopandas\io\file.py:166, in _read_file(filename, bbox, mask, rows, **kwargs)
104 def _read_file(filename, bbox=None, mask=None, rows=None, **kwargs):
105 """
106 Returns a GeoDataFrame from a file or URL.
107
(...)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
169 if _is_url(filename):
File C:\Anaconda3\lib\site-packages\geopandas\io\file.py:80, in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the 'fiona' package, but it is not installed or does "
82 f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"
83 )
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: DLL load failed while importing ogrext: The specified module could not be found.
I have geopanda installed and not sure what is the problem.

Any idea why is this error? Could not find a format to read the specified file in mode 'i'

Im trying to read my dataset file through 'IMAGE_PATH' but it seems its not working. 'med/s' is my dataset file. Im using google colab as IDE.
IMAGE_PATH = 'meds/'
reader = easyocr.Reader(['en'], gpu=False)
result = reader.readtext(IMAGE_PATH)
result
```
i get this error
ValueError
Traceback (most recent call last)
<ipython-input-12-7400931fefc3> in <module>()
1 reader = easyocr.Reader(['en'], gpu=False)
----> 2 result = reader.readtext(IMAGE_PATH)
3 result
7 frames
/usr/local/lib/python3.7/dist-packages/imageio/core/functions.py in get_reader(uri, format, mode, **kwargs)
137 if format is None:
138 raise ValueError(
--> 139 "Could not find a format to read the specified file " "in mode %r" % mode
140 )
141
ValueError: Could not find a format to read the specified file in mode 'i'

NotFoundError while using pickle dump to save a model

I have created a model named 'model' but when I'm trying to save it using pickle it just gives an 'NotFoundError'.
import pickle
with open("test.pkl","wb") as file:
pickle.dump(model, file)
This is the error message I get upon running the code.
Error message
INFO:tensorflow:Assets written to: ram://471dfd58-f3fe-4d9f-9075-60a1568cc629/assets
---------------------------------------------------------------------------
NotFoundError Traceback (most recent call last)
<ipython-input-47-0abd122520e5> in <module>
1 import pickle
2 with open("test.pkl","wb") as file:
----> 3 pickle.dump(model, file)
~\anaconda3\lib\site-packages\keras\engine\training.py in __reduce__(self)
313 if self.built:
314 return (pickle_utils.deserialize_model_from_bytecode,
--> 315 pickle_utils.serialize_model_as_bytecode(self))
316 else:
317 # SavedModel (and hence serialize_model_as_bytecode) only support
~\anaconda3\lib\site-packages\keras\saving\pickle_utils.py in serialize_model_as_bytecode(model)
75 with tf.io.gfile.GFile(dest_path, "rb") as f:
76 info = tarfile.TarInfo(name=os.path.relpath(dest_path, temp_dir))
---> 77 info.size = f.size()
78 archive.addfile(tarinfo=info, fileobj=f)
79 tf.io.gfile.rmtree(temp_dir)
~\anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py in size(self)
97 def size(self):
98 """Returns the size of the file."""
---> 99 return stat(self.__name).length
100
101 def write(self, file_content):
~\anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py in stat(filename)
908 errors.OpError: If the operation fails.
909 """
--> 910 return stat_v2(filename)
911
912
~\anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py in stat_v2(path)
924 errors.OpError: If the operation fails.
925 """
--> 926 return _pywrap_file_io.Stat(compat.path_to_str(path))
927
928
NotFoundError:
Any help would be massively appreciated
Not a solution but hopefully it still helps.
I had the same problem, and the same error. I ended up avoiding it by using Keras save and load methods instead of pickle. I don't know what your model is but you might want to try the same. It might be due to what is pickeleable. Maybe the answer given to this helps, they argue for saving tensorflow object separately.

Pillow Python (Watermarking) - Error Messages

so I am trying to pick a folder, select every photo, watermark it with an individual text and safe it in a different folder.
I have watched a lot of YouTube Videos and googled a lot but I can't help it anymore... Im always getting error messages and I can't see why.
So my current code is:
import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import os
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
draw = ImageDraw.Draw(f)
text = "Test, 22.01.2021"
font = ImageFont.truetype("arial.ttf",75)
textwidth, textheight = draw.textsize(text, font)
width, height = f.size
x=width/2-textwidth/2
y=height-textheight-300
draw.text((x,y), text, font=font)
fn, fext = os.path.splitext(f)
i.save('Test/{}.jpg'.format(fn))
Errors:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageDraw.py in Draw(im, mode)
464 try:
--> 465 return im.getdraw(mode)
466 except AttributeError:
AttributeError: 'str' object has no attribute 'getdraw'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-5-5c49936ed159> in <module>
9 if f.endswith('.jpg'):
10 i = Image.open(f)
---> 11 draw = ImageDraw.Draw(f)
12 text = "Jonas Knaab, 22.01.2021"
13 font = ImageFont.truetype("arial.ttf",75)
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageDraw.py in Draw(im, mode)
465 return im.getdraw(mode)
466 except AttributeError:
--> 467 return ImageDraw(im, mode)
468
469
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageDraw.py in __init__(self, im, mode)
57 defaults to the mode of the image.
58 """
---> 59 im.load()
60 if im.readonly:
61 im._copy() # make it writeable
AttributeError: 'str' object has no attribute 'load'
------------------
Maybe you guys can help me somehow?
Cheers
!!EDIT!!
after changing ..."Draw(f)" to "Draw(i) I do not get the same error messages but it still doesn't work.
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-9-3b2bbb3d5783> in <module>
11 draw = ImageDraw.Draw(i)
12 text = "Jonas Knaab, 22.01.2021"
---> 13 font = ImageFont.truetype("arial.ttf",75)
14 textwidth, textheight = draw.textsize(text, font)
15 width, height = f.size
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageFont.py in truetype(font, size, index, encoding, layout_engine)
640
641 try:
--> 642 return freetype(font)
643 except OSError:
644 if not isPath(font):
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageFont.py in freetype(font)
637
638 def freetype(font):
--> 639 return FreeTypeFont(font, size, index, encoding, layout_engine)
640
641 try:
/opt/anaconda3/lib/python3.7/site-packages/PIL/ImageFont.py in __init__(self, font, size, index, encoding, layout_engine)
186 return
187 self.font = core.getfont(
--> 188 font, size, index, encoding, layout_engine=layout_engine
189 )
190 else:
OSError: cannot open resource
You're using string as an argument to ImageDraw.Draw(). Use i variable instead of f.
i = Image.open(f)
draw = ImageDraw.Draw(i)

Unable to export a python chainladder triangle to excel sheet

I am exploring the chainladder package. I tried to export a triangle structure into an excel sheet. But it throws an error. Has anyone ever faced this kind of problem. I am using chainladder==0.7.9 with pandas==0.24.2. Here is my simple code by reading their documentation https://chainladder-python.readthedocs.io/en/latest/tutorials/index.html
import pandas as pd
import numpy as np
import chainladder as cl
raa = cl.load_sample('raa')
cl.load_template('triangle', triangle=raa.latest_diagonal).to_excel('raa_example.xlsx')
I get the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\chainladder\utils\exhibits.py in load_template(template, env, **kwargs)
24 try:
---> 25 return load_yaml(template, env, **kwargs)
26 except:
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in load_yaml(template, env, str_only, **kwargs)
108 else:
--> 109 return _make_xlc(yaml.load(template, Loader=yaml.SafeLoader), **kwargs)
110
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in _make_xlc(template, **kwargs)
51 return core.Tabs(*[('Sheet1', item) for item in tabs])
---> 52 key = list(template.keys())[0]
53 if key in ['Row', 'Column']:
AttributeError: 'str' object has no attribute 'keys'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-17-270670213d97> in <module>
----> 1 cl.load_template('triangle', triangle=raa.latest_diagonal).to_excel('raa_example.xlsx')
2 #,type(raa.latest_diagonal)
3 type(raa_model.ultimate_)
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\chainladder\utils\exhibits.py in load_template(template, env, **kwargs)
26 except:
27 template = os.path.join(path, "templates", template.lower() + ".yaml")
---> 28 return load_yaml(template, env, **kwargs)
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in load_yaml(template, env, str_only, **kwargs)
107 return template
108 else:
--> 109 return _make_xlc(yaml.load(template, Loader=yaml.SafeLoader), **kwargs)
110
111 def load_json(template, env=None, **kwargs):
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in _make_xlc(template, **kwargs)
50 except:
51 return core.Tabs(*[('Sheet1', item) for item in tabs])
---> 52 key = list(template.keys())[0]
53 if key in ['Row', 'Column']:
54 return getattr(core, key)(*[_make_xlc(element, **kwargs)
AttributeError: 'str' object has no attribute 'keys'
Please let me know if I am missing something silly.
load_template is used to load a YAML template containing the specs for your Excel file. This particular template file is designed to create a standard exhibit for regular triangles, not diagonals. Templates are used to contain complex layouts, formatting, logic.
This should resolve the issue:
cl.load_template('triangle', triangle=raa).to_excel('raa_example.xlsx')
If you would simply like to export just the diagonal to Excel, you can do so without a template:
raa.latest_diagonal.to_excel('raa_example.xlsx')
# or
cl.DataFrame(raa.latest_diagonal).to_excel('raa_example.xlsx')

Categories

Resources