失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python把wav本地转文字_在python中将大型wav文件转换为文本

python把wav本地转文字_在python中将大型wav文件转换为文本

时间:2024-05-28 16:27:53

相关推荐

python把wav本地转文字_在python中将大型wav文件转换为文本

谷歌的语音对文字非常有效,试试下面的链接

你可以选择语言(在你的情况下是英语美国)和上传文件。在

就像@bigdataolddriver评论的那样,100%的准确率还不可能,而且价值数百万美元。在

googlespeech-to-text有三种类型的api

同步,异步和流媒体,其中异步允许您约480分钟音频转换,而其他人将只允许您~1分钟。下面是执行转换的示例代码。在filepath = "~/audio_wav/" #Input audio file path

output_filepath = "~/Transcripts/" #Final transcript path

bucketname = "callsaudiofiles" #Name of the bucket created in the step before

# Import libraries

from pydub import AudioSegment

import io

import os

from google.cloud import speech

from google.cloud.speech import enums

from google.cloud.speech import types

import wave

from google.cloud import storage

支持WAVR16或WAVR16语音编码文本文件。在

下面是获取帧速率和信道编码的代码。在

^{pr2}$

下面的代码是执行异步转换的。在def google_transcribe(audio_file_name):

file_name = filepath + audio_file_name

# The name of the audio file to transcribe

frame_rate, channels = frame_rate_channel(file_name)

if channels > 1:

stereo_to_mono(file_name)

bucket_name = bucketname

source_file_name = filepath + audio_file_name

destination_blob_name = audio_file_name

upload_blob(bucket_name, source_file_name, destination_blob_name)

gcs_uri = 'gs://' + bucketname + '/' + audio_file_name

transcript = ''

client = speech.SpeechClient()

audio = types.RecognitionAudio(uri=gcs_uri)

config = types.RecognitionConfig(

encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,

sample_rate_hertz=frame_rate,

language_code='en-US')

# Detects speech in the audio file

operation = client.long_running_recognize(config, audio)

response = operation.result(timeout=10000)

for result in response.results:

transcript += result.alternatives[0].transcript

delete_blob(bucket_name, destination_blob_name)

return transcript

这就是你把它们写进文件的方法def write_transcripts(transcript_filename,transcript):

f= open(output_filepath + transcript_filename,"w+")

f.write(transcript)

f.close()

如果您需要进一步澄清,请告诉我。在

如果觉得《python把wav本地转文字_在python中将大型wav文件转换为文本》对你有帮助,请点赞、收藏,并留下你的观点哦!

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