@rrrrri08

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Pythonでスペクトログラム表示する

音声について調べるためにPythonでスペクトログラムを出すコードを書いているのですが、
エラーが出ていて、このエラーの意味と解決策を教えていただきたいです。

発生している問題・エラー

Traceback (most recent call last):
  File "c:\Users\.DESKTOP-BS9K2U1\Desktop\Python\voice.py", line 32, in <module>
    plt.colorbar(format='%+2.0f dB')
  File "C:\Users\.DESKTOP-BS9K2U1\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\pyplot.py", line 2137, in colorbar      
    ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
  File "C:\Users\.DESKTOP-BS9K2U1\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\figure.py", line 1279, in colorbar      
    and isinstance(ax, mpl.axes._base._AxesBase)
  File "C:\Users\.DESKTOP-BS9K2U1\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\_api\__init__.py", line 226, in __getattr__
    raise AttributeError(
AttributeError: module 'matplotlib' has no attribute 'axes'. Did you mean: 'axis'?

該当するソースコード

import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np

# ファイル読み込み
filename = r'C:\Users\.DESKTOP-BS9K2U1\Desktop\Python\test.wav'
y,sr = librosa.load(filename)
# y = 音声データが入る
# sr = サンプリングレート値 (1秒間の音声データ数)が入る

print('サンプリングレート:',sr) #サンプリングレート
print('音声:',y) 
print('トータルサンプル数:',len(y)) #サンプル数
print('秒数:',len(y)/sr) #秒数

#時間領域でのグラフ
plt.figure(figsize=(6,2))
librosa.display.waveshow(y=y, sr=sr)
plt.ylabel('amplitude')
plt.xlabel('frequency')
plt.savefig("tenki.png")
plt.show()

D = librosa.stft(y)  # STFT
S, phase = librosa.magphase(D)  # 複素数を強度と位相へ変換
Sdb = librosa.amplitude_to_db(S)  # 強度をdb単位へ変換

# スペクトログラムを表示
plt.figure(figsize=(8, 4))
librosa.display.specshow(Sdb,sr=sr,x_axis='time', y_axis='log')
plt.colorbar(format='%+2.0f dB')
plt.savefig('Spectrogram.png')
plt.show()
0 likes

1Answer

スペクトログラムですか?大変ですね!
音声の関心事は私は
SpeechSynthesisUtterance + webSocket です。

さて、

pip  install  axes
pip  install  mpl

とかで解決しないかな?
import matplotlib.pyplot as plt
のバージョンが古い?

AttributeError:
module 'matplotlib' has no attribute 'axes'.
Did you mean: 'axis'?

mpl.axes
でぐぐるとこんなのでました。

0Like

Comments

  1. @rrrrri08

    Questioner

    提案して頂いた
    pip install axes
    pip install mpl
    を実行したのですが、
    ERROR: Could not find a version that satisfies the requirement axes (from versions: none)
    ERROR: No matching distribution found for axes
    このようなエラーが出てしまいました。
    matplotlibは最新バージョンになっています!

    サイトありがとうございます、参考にします。

Your answer might help someone💌