在python中将声音转换为音素列表

2024-05-29 00:03:14 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将任何声音信号转换为列表音素?

即从数字信号到录音所用音素列表的实际方法和/或代码。
例如:

lPhonemes = audio_to_phonemes(aSignal)

例如

from scipy.io.wavfile import read
iSampleRate, aSignal = read(sRecordingDir)

aSignal = #numpy array for the recorded word 'hear'
lPhonemes = ['HH', 'IY1', 'R']

我需要函数audio_to_phonemes

不是所有的声音都是语言文字,所以我不能只使用something that uses the google API例如。

编辑
我不想把声音变成文字,我想把声音变成音素。大多数库似乎都没有输出。您推荐的任何库都需要能够输出由声音组成的音素的有序列表。它需要用python编写。

我也想知道音素转换过程是如何工作的。如果不是为了实现的目的,那么为了利益。


Tags: theto方法代码声音列表read信号
2条回答

准确的音素识别不容易存档,因为音素本身的定义相当松散。即使在好的音频中,现在最好的系统也有18%的音素错误率(你可以在Alex Graves发布的TIMIT上查看LSTM-RNN结果)。

在cmusphenx中,Python中的音素识别是这样完成的:

from os import environ, path

from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *

MODELDIR = "../../../model"
DATADIR = "../../../test/data"

# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-allphone', path.join(MODELDIR, 'en-us/en-us-phone.lm.dmp'))
config.set_float('-lw', 2.0)
config.set_float('-beam', 1e-10)
config.set_float('-pbeam', 1e-10)

# Decode streaming data.
decoder = Decoder(config)

decoder.start_utt()
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
while True:
  buf = stream.read(1024)
  if buf:
    decoder.process_raw(buf, False, False)
  else:
    break
decoder.end_utt()

hypothesis = decoder.hyp()
print ('Phonemes: ', [seg.word for seg in decoder.seg()])

为了运行这个示例,您需要从github签出最新的pocketsphinx。结果应该是这样的:

  ('Best phonemes: ', ['SIL', 'G', 'OW', 'F', 'AO', 'R', 'W', 'ER', 'D', 'T', 'AE', 'N', 'NG', 'IY', 'IH', 'ZH', 'ER', 'Z', 'S', 'V', 'SIL'])

另请参见wiki page

I need to create the function audio_to_phonemes

你基本上是说:

I need to re-implement 40 years of speech recognition research

你不应该自己实现这一点(除非你即将成为语音识别领域的教授并有一个革命性的新方法),而是应该使用现有的许多框架之一。看看狮身人面像/口袋狮身人面像!

相关问题 更多 >

    热门问题