100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 手把手教你语音识别

手把手教你语音识别

时间:2022-07-20 22:07:15

相关推荐

手把手教你语音识别

朋友们,语音识别这块最近研究了一段时间,有所收获,比较重要的一点是,对于模型,现在大家都知道大概,很多非常小的细节可能很多人注意的少,从这篇文章开始,我打算讲一讲模型的细节,从数据处理到怼入model,每一步是如何完成的,今天就从语音识别开始吧。

1、读取数据

import soundfileaudio, audio_sample_rate = soundfile.read("C:\Users\air\Desktop\asr16.wav", dtype="int16",always_2d=True)

这一步完成后,其实就是用open等方法把数据读出来,经过简单的一些处理变成audio的ndarry格式,其实读取的算法很简单,就是用buffer逐帧读取。具体源代码可以参考:github:soundfile.py

2、数据处理

我们知道,数据不可能直接怼入模型,这样话,特征提取效果很差,所以要进行预处理,下面就一步步的处理数据。

import numpy as npaudio = audio.mean(axis=1, dtype=np.int16)

这个地方,很有意思,读取的时候是二通道,也就是二维数据,经过一个axis=1,我对第二维度进行平均,audio实现了降维,变成一维数据了。

def pcm16to32(audio): assert (audio.dtype == np.int16) audio = audio.astype("float32") bits = np.iinfo(np.int16).bits audio = audio / (2**(bits - 1)) return audiodef pcm32to16(audio): assert (audio.dtype == np.float32) bits = np.iinfo(np.int16).bits audio = audio * (2**(bits - 1)) audio = np.round(audio).astype("int16") return audiodef pcm32to16(audio): assert (audio.dtype == np.float32) bits = np.iinfo(np.int16).bits audio = audio * (2**(bits - 1)) audio = np.round(audio).astype("int16") return audio

上面这一波操作主要是做了两件事,第一,把模拟信号重新编码,并转换为float格式,然后,重采样在编码为int16。

import picklewith open("configs.pkl", "rb") as tf: configs = pickle.load(tf) with open("cls.pkl", "rb") as tf: cls = pickle.load(tf)

3、模型预测

这个地方,其实是我把模型的configs文件和model文件保存了,所以我直接可以加载模型。

result_transcripts = model.decode(audio,paddle.to_tensor([363],dtype="int64"), text_feature=text_feature,decoding_method="attention_rescoring", beam_size=10, ctc_weight=0.5,decoding_chunk_size=-1,num_decoding_left_chunks=-1,simulate_streaming=False)

好了,你可以看到模型预测结束了,其实就是这么简单,不过,这是一个叠加的流程,后面这些东西展开再讲,今天就到这里。

4、模型简介

前面把整个流程讲完了,但是还有个比较重要的,就是我先把audio模型的大致框架给描述下,这样的话,有了框架后面讲起来会比较容易。

(1)模型架构

关于模型架构,下面的英文讲述的比较明白:

The implemented architecture of Deepspeech2 online model is based on Deepspeech2 model with some changes. The model is mainly composed of 2D convolution subsampling layers and stacked single-direction rnn layers.

To illustrate the model implementation clearly, 3 parts are described in detail.

Data PreparationEncoderDecoder

In addition, the training process and the testing process are also introduced.

(2)数据处理

For English data, the vocabulary dictionary is composed of 26 English characters with " ’ ", space, and . The represents the blank label in CTC, the represents the unknown character and the represents the start and the end characters. For mandarin, the vocabulary dictionary is composed of Chinese characters statistics from the training set, and three additional characters are added. The added characters are , and . For both English and mandarin data, we set the default indexes that =0, =1 and = last index.

如上,意思大概是,英文的字典包括26个字母、引号和空格等。并且,在CTC里面,blank表示未知字符。对于普通话呢,那就是中文的字典了,至于后面还有cmvn等等操作,这个下期再讲。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。