我正在使用python3通过提供的python包( Google )转录一个带有的音频文件。
有一个选项可以定义自定义短语,如docs:https://cloud.google.com/speech-to-text/docs/speech-adaptation中所述,这些短语应该用于转录。
为了测试目的,我使用了一个包含文本的小型音频文件:
。。在这节课中,我们将讨论布伦斯惠勒变换和调频指数。
如果我想用正确的表示法来识别一个特定的名字,我会给出下面的短语来查看效果。在本例中,我希望将钻孔更改为barrows。
config = speech.RecognitionConfig(dict(
encoding=speech.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED,
sample_rate_hertz=24000,
language_code="en-US",
enable_word_time_offsets=True,
speech_contexts=[
speech.SpeechContext(dict(
phrases=["barrows", "barrows wheeler", "barrows wheeler transform"]
))
]
))不幸的是,这似乎没有任何影响,因为输出仍然是相同的,没有上下文短语。
我是不是用错了短语,或者它是否很有信心,它听到的单词确实是 burrows ,这样它就会忽略我的短语?
PS:我也尝试使用speech_v1p1beta1.AdaptationClient和speech_v1p1beta1.SpeechAdaptation,而不是将短语放入配置中,但这只会给出一个内部服务器错误,而不需要提供更多的错误信息。https://cloud.google.com/speech-to-text/docs/adaptation
发布于 2021-11-26 18:51:58
我已经创建了一个音频文件,以重新创建您的场景,我能够提高识别使用模型自适应。为了实现这个特性,我建议查看这个示例和这个帖子,以更好地理解适应模型。
现在,为了提高对您短语的认知度,我执行了以下操作:
在这节课中,我们将讨论布伦斯惠勒变换和调频指数。
PhraseSet和CustomClass,其中包含了您想要改进的单词,在本例中是"barrows“。还可以使用语音文本图形用户界面创建/更新/删除短语集和自定义类。下面是我用于改进的代码。from os import pathconf_names
from google.cloud import speech_v1p1beta1 as speech
import argparse
def transcribe_with_model_adaptation(
project_id="[PROJECT-ID]", location="global", speech_file=None, custom_class_id="[CUSTOM-CLASS-ID]", phrase_set_id="[PHRASE-SET-ID]"
):
"""
Create`PhraseSet` and `CustomClasses` to create custom lists of similar
items that are likely to occur in your input data.
"""
import io
# Create the adaptation client
adaptation_client = speech.AdaptationClient()
# The parent resource where the custom class and phrase set will be created.
parent = f"projects/{project_id}/locations/{location}"
# Create the custom class resource
adaptation_client.create_custom_class(
{
"parent": parent,
"custom_class_id": custom_class_id,
"custom_class": {
"items": [
{"value": "barrows"}
]
},
}
)
custom_class_name = (
f"projects/{project_id}/locations/{location}/customClasses/{custom_class_id}"
)
# Create the phrase set resource
phrase_set_response = adaptation_client.create_phrase_set(
{
"parent": parent,
"phrase_set_id": phrase_set_id,
"phrase_set": {
"boost": 0,
"phrases": [
{"value": f"${{{custom_class_name}}}", "boost": 10},
{"value": f"talk about the ${{{custom_class_name}}} wheeler transform", "boost": 15}
],
},
}
)
phrase_set_name = phrase_set_response.name
# print(u"Phrase set name: {}".format(phrase_set_name))
# The next section shows how to use the newly created custom
# class and phrase set to send a transcription request with speech adaptation
# Speech adaptation configuration
speech_adaptation = speech.SpeechAdaptation(
phrase_set_references=[phrase_set_name])
# speech configuration object
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=24000,
language_code="en-US",
adaptation=speech_adaptation,
enable_word_time_offsets=True,
model="phone_call",
use_enhanced=True
)
# The name of the audio file to transcribe
# storage_uri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE]
with io.open(speech_file, "rb") as audio_file:
content = audio_file.read()
audio = speech.RecognitionAudio(content=content)
# audio = speech.RecognitionAudio(uri="gs://biasing-resources-test-audio/call_me_fionity_and_ionity.wav")
# Create the speech client
speech_client = speech.SpeechClient()
response = speech_client.recognize(config=config, audio=audio)
for result in response.results:
# The first alternative is the most likely one for this portion.
print(u"Transcript: {}".format(result.alternatives[0].transcript))
# [END speech_transcribe_with_model_adaptation]
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("path", help="Path for audio file to be recognized")
args = parser.parse_args()
transcribe_with_model_adaptation(speech_file=args.path)element already exists消息的错误。(python_speech2text) user@penguin:~/replication/python_speech2text$ python speech_model_adaptation_beta.py audio.flac
Transcript: in this lecture will talk about the Burrows wheeler transform and the FM index

(python_speech2text) user@penguin:~/replication/python_speech2text$ python speech_model_adaptation_beta.py audio.flac
Transcript: in this lecture will talk about the barrows wheeler transform and the FM index

最后,我想添加一些关于改进和我执行的代码的说明:
flac音频文件,因为它是推荐的最佳结果。model="phone_call"和use_enhanced=True,因为这是Cloud使用我自己的音频文件识别的模型。此外,增强的模型可以提供更好的结果,您可以看到文档的更多细节。注意,此配置可能与您的音频文件不同。我希望这些信息能帮助你提高认识。
https://stackoverflow.com/questions/70048973
复制相似问题