要通过 Python 第三方库获得一句话在一段录音中的起始时间,可以使用 SpeechRecognition 库。以下是一个示例代码:

import speech_recognition as sr

# 定义语音识别器
r = sr.Recognizer()

# 加载录音文件
audio_file = sr.AudioFile('audio.wav')

# 打开录音文件并将其转换为音频源
with audio_file as source:
    audio = r.record(source)

# 使用 Google 语音识别 API 解析音频
text = r.recognize_google(audio, language='zh-CN')

# 获取音频中第一次出现文本的开始时间
matches = re.finditer(text, audio_file)
for match in matches:
    start_time = match.start() / audio_file.SAMPLE_RATE

print('The text "{}" starts at {:.2f} seconds.'.format(text, start_time))

该代码使用 Google 语音识别 API 解析音频,并使用正则表达式查找音频中第一次出现文本的开始时间。请注意,您需要在 Google Cloud 平台上注册并获取 API 密钥才能使用 Google 语音识别 API。

通过 python 第三方库获得一句话在一段录音中的起始时间

原文地址: http://www.cveoy.top/t/topic/GAQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录