只能读取16位wav文件,但收到32 - Tensorflow

问题描述 投票:0回答:1

我已将所有 wav 文件转换为 16 位 PCM 并使用以下代码进行检查

import soundfile as sf
ob = sf.SoundFile('./data/road.wav')
print('Sample rate: {}'.format(ob.samplerate))
print('Channels: {}'.format(ob.channels))
print('Subtype: {}'.format(ob.subtype_info))

但是当我打电话的时候

history = my_model.fit(train_ds,
                       validation_data=valid_ds, epochs=20)

出现以下错误

 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:
2 root error(s) found.
  (0) INVALID_ARGUMENT:  2 root error(s) found.
  (0) INVALID_ARGUMENT:  Can only read 16-bit WAV files, but received 32
     [[{{node DecodeWav}}]]
     [[Func/StatefulPartitionedCall/input_control_node/_2/_7]]
  (1) INVALID_ARGUMENT:  Can only read 16-bit WAV files, but received 32
     [[{{node DecodeWav}}]]
0 successful operations.
0 derived errors ignored.

如何解决这个错误?如何检查 wav 是否是 32 位?

python tensorflow audio wav
1个回答
0
投票

转换位深度相当简单:

import soundfile

data, samplerate = soundfile.read('./data/road.wav')
soundfile.write('./data/road16.wav', data, samplerate, subtype='PCM_16')
© www.soinside.com 2019 - 2024. All rights reserved.