python - Pyaudio - 将声音数据转换为字符串的算法

标签 python algorithm python-3.4 pyaudio

<分区>

我正在使用 Pyaudio 录制声音并从中提取数据。现在我录制了一个声音并用 matplotlib 显示它。

import pyaudio,numpy
import matplotlib.pyplot as plt

FORMAT = pyaudio.paFloat32
SAMPLEFREQ = 44100
FRAMESIZE = 1024
NOFFRAMES = 220
p = pyaudio.PyAudio()
print('running')

stream = p.open(format=FORMAT,channels=1,rate=SAMPLEFREQ,input=True,frames_per_buffer=FRAMESIZE)
data = stream.read(NOFFRAMES*FRAMESIZE)
decoded = numpy.fromstring(data, 'Float32')
for x in decoded:
    if x != 0.0:   #
        print (x)  #--- decoded is very huge, I just print the first float number
        break      #


stream.stop_stream()
stream.close()
p.terminate()
print('done')
plt.plot(decoded)
plt.show()

此代码的示例输出是;

enter image description here

我的主要目标是弄清楚 decoded 中的 float 并将它们转换为字符串。比如我想检测我是否记录了aaa,我想对那个记录的数据的数据进行处理,最后将其转换为aaadecoded 是一个巨大的 float 列表,所以我找不到处理它的方法。我愿意听取有关库的建议,以及实现此目标的正确算法是什么。

在我看来,我使用了错误的库,但找不到适合我目标的正确库/方法。

最佳答案

这听起来像是您在征求有关使用 python 进行“语音(音频)到文本(字符串)”转换的建议。有一些很棒的 AP​​I 和 python 库可用于执行语音到文本的转换:

Getting started with speech recognition and python

Pygrs

SpeechRecognition 3.4.6

关于python - Pyaudio - 将声音数据转换为字符串的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37618990/

相关文章:

python - 返回列表中重复元素并在列表中查找缺失元素的最快方法?

python - pyserial 2.7 文档错误,python 3.4 TypeError : an integer is required

python - 在 Python 3 中将 Unicode 序列转换为字符串

python - 要修补哪个模块

python - Django 主键序列化器 "This field may not be null"同时allow_null=True

python - 无法在 MacOS 上使用 pyenv Python 安装 tkinter

python - 展平 pandas DataFrame

python - Pandas:根据条件将行转换为单列

algorithm - CSES范围查询问题: Salary Queries

performance - 我应该如何使用递归扫描算法实现 Cilk 并行?