【问题标题】:How to map audio to target text transcription如何将音频映射到目标文本转录
【发布时间】:2019-04-22 07:59:50
【问题描述】:

我是深度学习的新手,我正在使用 tensorflow API、LSTM 模型和 ctc 损失函数制作一个基本的端到端语音识别器。我已将我的音频功能提取到 mfccs。我真的不知道如何将我的音频映射到转录,我知道 ctc 用于此目的,我知道 ctc 是如何工作的,但不知道实现它的代码。

这是我提取特征的代码

import os
import numpy as np
import glob
import scipy.io.wavfile as wav
from python_speech_features import mfcc, logfbank

# Read the input audio file
for f in glob.glob('Downloads/DataVoices/Training/**/*.wav', recursive=True):
    (rate,sig) = wav.read(f)
    sig = sig.astype(np.float64)
    # Take the first 10,000 samples for analysis
    #sig = sig[:10000]
    mfcc_feat = mfcc(sig,rate,winlen=0.025, winstep=0.01,
                     numcep=13, nfilt=26, nfft=512, lowfreq=0, highfreq=None,
                     preemph=0.97, ceplifter=22, appendEnergy=True)
    fbank_feat = logfbank(sig, rate)
    acoustic_features = np.concatenate((mfcc_feat, fbank_feat), axis=1) # time_stamp x n_features
    print(acoustic_features)

我还制作了一个培训 list.txt 文件,其中我提供了带有音频路径的转录,例如:

这是例子/001/001.wav

这是例子/001/001(1).wav

其中 001 是文件夹,001.wav 和 0001(1).wav 是一个话语的两个波形文件。

【问题讨论】:

  • 你能澄清你的问题吗?成绩单在哪里?
  • 我已经编辑了我的问题,现在您可能已经清楚了,如果没有,请告诉我。
  • 我有一个执行的例子。但是你必须添加你的功能并验证批量大小等。这是一个最基本的例子。

标签: python-3.x tensorflow deep-learning lstm speech-to-text


【解决方案1】:

我将其发布为一个人为的示例,假设这可以让您了解如何读取 CSV 文件和 CSV 中的文件名。您可以修改它以满足您的需要。

假设我有这个 CSV 文件。第一列是你的成绩单。文件路径是您的音频文件。就我而言,它只是一个带有随机文本的文本文件。

Script1,D:/PycharmProjects/TensorFlow/script1.txt
Script2,D:/PycharmProjects/TensorFlow/script2.txt

这是我用来测试它的代码。请记住这是一个例子。

import tensorflow as tf


batch_size = 1
record_defaults = [ ['Test'],['D:/PycharmProjects/TensorFlow/script1.txt']]


def readbatch(data_queue) :

    reader = tf.TextLineReader()
    _, rows = reader.read_up_to(data_queue, batch_size)
    transcript,wav_filename = tf.decode_csv(rows, record_defaults,field_delim=",")
    audioreader = tf.WholeFileReader()
    print(wav_filename)
    _, audio = audioreader.read( tf.train.string_input_producer(wav_filename) )
    return [audio,transcript]

data_queue = tf.train.string_input_producer(['D:\\PycharmProjects\\TensorFlow\\script.csv'], shuffle=False)

batch_data = readbatch(data_queue)

batch_values = tf.train.batch(batch_data, shapes=[tf.TensorShape(()),tf.TensorShape(batch_size,)],  batch_size=batch_size, enqueue_many=False )

init = tf.initialize_all_variables()

with tf.Session() as sess:
    sess.run(init)

    sess.run(tf.initialize_local_variables())
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    try:
        step = 0
        while not coord.should_stop():
            step += 1
            feat = sess.run([batch_values])
            audio = feat[0][0]
            print(audio)
            script = feat[0][1]
            print(script)
    except tf.errors.OutOfRangeError:
        print(' training for 1 epochs, %d steps', step)
    finally:
        coord.request_stop()
        coord.join(threads)

【讨论】:

    猜你喜欢
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2012-10-20
    • 2021-01-29
    • 2016-04-28
    相关资源
    最近更新 更多