简体   繁体   English

如何使用melspectogram将wav文件转换为RGB图像?

[英]How to convert a wav file into RGB image with melspectogram?

I am working on sound classification with wav files ranging from 1 second to 4 second.我正在使用范围从 1 秒到 4 秒的 wav 文件进行声音分类。 i want to convert wav to 224x224x3 image that i can fee into Resnet for classification The conversion should be using melspectogram Thanks for help我想将 wav 转换为 224x224x3 图像,我可以将其收费到 Resnet 进行分类转换应该使用 melspectogram感谢您的帮助

You can use librosa to produce mel spectrogram like this:您可以使用librosa生成 mel 谱图,如下所示:

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

y, sr = librosa.load(librosa.util.example_audio_file()) # your file
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128, fmax=8000)
librosa.display.specshow(librosa.power_to_db(S, ref=np.max), fmax=8000)
plt.savefig('mel.png')

Mind though that these are false colours, RGB does not make sense here - nor any multi-channel.请注意,尽管这些是假色,但 RGB 在这里没有意义 - 也没有任何多通道。 Use architecture that works with a single channel.使用适用于单个通道的架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM