程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了OP_REQUIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决OP_requIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32?

开发过程中遇到OP_requIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32的问题如何解决?下面主要结合日常开发的经验,给出你关于OP_requIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32的解决方法建议,希望对你解决OP_requIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32有所启发或帮助;

我正在构建一个音频分类器,其中将训练神经网络将音频分为两类。以下是我的“Train.py”模块:

import os 
import tensorflow as tf
import numpy as np

from configs import PARENT_DIR_TO_SAVE_CHUNKS,VALIDATION_PERCENT_OUT_OF_@R_751_1@R_772_11226@6@L,test_PERCENT_OUT_OF_@R_751_1@R_772_11226@6@L,PARENT_DIR_TO_PCM_GOOD_CHUNKS,PARENT_DIR_TO_PCM_BAD_CHUNKS
from utils import decode_audio,do_process_path_of_audio,get_label,get_waveform_and_label,plot,get_spectrogram

def main():
    goods = [os.path.join(PARENT_DIR_TO_SAVE_CHUNKS,"GOOD",filE) for file in os.Listdir(os.path.join(PARENT_DIR_TO_SAVE_CHUNKS,"GOOD"))]
    bads = [os.path.join(PARENT_DIR_TO_SAVE_CHUNKS,"BAD","BAD"))]
    all = goods + bads
    filenames = tf.convert_to_tensor(all)
    filenames = tf.random.shuffle(filenames)

    print(filenames)
    
    length_of_val_samples = int((VALIDATION_PERCENT_OUT_OF_@R_751_1@R_772_11226@6@L / 100) * len(filenames))
    length_of_test_samples = int((test_PERCENT_OUT_OF_@R_751_1@R_772_11226@6@L / 100) * len(filenames))
    
    Train_files = filenames[:len(filenames) - length_of_val_samples - length_of_test_samples]
    val_files = filenames[len(filenames) - length_of_val_samples - length_of_test_samples:\
                            len(filenames) - length_of_val_samples]
    test_files = filenames[-(length_of_test_samples):]

    print('Training set size:',len(Train_files))
    print('ValIDation set size:',len(val_files))
    print('Test set size:',len(test_files))

    (files,waveforms) = do_process_path_of_audio(Train_files)
    print(waveforms)
    # plot(waveforms)
    # print(waveforms.take(1))
    for waveform,label in waveforms.take(1):
        label = label.numpy().decode('utf-8')
        spectrogram = get_spectrogram(waveform)

    # print('Label:',label)
    # print('Waveform shape:',waveform.shapE)
    # print('Spectrogram shape:',spectrogram.shapE)
    
    
if __name__ == "__main__":
    
    main()

以下包含我的“preprocess.py”模块中的相关函数:

import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
import os

def decode_audio(audio_binary):
  audio,_ = tf.audio.decode_wav(audio_binary)
  print(_)
  print(audio)
  return tf.squeeze(audio,axis=-1)


def get_label(file_path):
    parts = tf.Strings.split(file_path,os.path.sep)
    print(file_path)

    return parts[-2] 


def get_waveform_and_label(file_path):
  label = get_label(file_path)
  audio_binary = tf.io.read_file(file_path)
  waveform = decode_audio(audio_binary)

  return waveform,label

def do_process_path_of_audio(files):
    autoTUNE = tf.data.autoTUNE
    files_ds = tf.data.Dataset.from_tensor_slices(files)
    waveform_ds = files_ds.map(get_waveform_and_label,num_parallel_calls=autoTUNE)
    return (files_ds,waveform_ds)


def plot(waveforms):
    rows = 3
    cols = 3
    n = rows*cols
    fig,axes = plt.subplots(rows,cols,figsize=(10,12))
    print("======>",waveforms.take(15))
    for i,(audio,label) in enumerate(waveforms.take(n)):
        r = i // cols
        c = i % cols
        ax = axes[r][c]
        ax.plot(audio.numpy())
        ax.set_yticks(np.arange(-1.2,1.2,0.2))
        label = label.numpy().decode('utf-8')
        ax.set_title(label)

    plt.show()


def get_spectrogram(waveform):

  zero_padding = tf.zeros([16000] - tf.shape(waveform),dtype=tf.float32)

  waveform = tf.cast(waveform,tf.float32)
  equal_length = tf.concat([waveform,zero_padding],0)
  spectrogram = tf.signal.stft(
      equal_length,frame_length=255,frame_step=128)
      
  spectrogram = tf.abs(spectrogram)

  return spectrogram

现在当我到达线路时:

for waveform,label in waveforms.take(1)

我收到以下错误: OP_requIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32

我检查了我的数据集音频的sample_rate,它们都在16000。我在互联网上搜索了所有内容,但发现没有人问过这样的问题。任何想法如何解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的OP_REQUIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32全部内容,希望文章能够帮你解决OP_REQUIRES 在 decode_wav_op.cc:55 失败:无效参数:只能读取 16 位 WAV 文件,但收到 32所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。