在 python 中加载 FLAC 文件,与 scipy 或 librosa 相同
Load FLAC file in python same as scipy or librosa
我想将一些 flac 声音文件输入到 keras 模型中。使用 wavfiles 我可以做到(一个音频文件使用两次的人为示例)
import scipy.io.wavfile
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
path = 'path/to/file.wav'
_, audio = scipy.io.wavfile.read(path)
dataset = [audio, audio]
x_train = np.array(dataset)
y_train = keras.utils.to_categorical([0, 1], num_classes=2)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=x_train[0].shape))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=32)
如何使用 flac 文件来执行此操作?
soundfile 包可以加载 numpy 数组兼容格式的 flac 文件
import numpy as np
import soundfile as sf
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
path = 'path/to/file.flac'
data, samplerate = sf.read(path)
dataset = [data, data]
x_train = np.array(dataset)
y_train = keras.utils.to_categorical([0, 1], num_classes=2)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=x_train[0].shape))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=32)
可分叉的 sscce https://www.kaggle.com/morenoh149/flac-keras-hello-world
我想将一些 flac 声音文件输入到 keras 模型中。使用 wavfiles 我可以做到(一个音频文件使用两次的人为示例)
import scipy.io.wavfile
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
path = 'path/to/file.wav'
_, audio = scipy.io.wavfile.read(path)
dataset = [audio, audio]
x_train = np.array(dataset)
y_train = keras.utils.to_categorical([0, 1], num_classes=2)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=x_train[0].shape))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=32)
如何使用 flac 文件来执行此操作?
soundfile 包可以加载 numpy 数组兼容格式的 flac 文件
import numpy as np
import soundfile as sf
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
path = 'path/to/file.flac'
data, samplerate = sf.read(path)
dataset = [data, data]
x_train = np.array(dataset)
y_train = keras.utils.to_categorical([0, 1], num_classes=2)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=x_train[0].shape))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=32)
可分叉的 sscce https://www.kaggle.com/morenoh149/flac-keras-hello-world