首页 > 编程知识 正文

网页视频转文字,网页视频提取文字

时间:2023-05-04 21:12:03 阅读:230075 作者:1891

代码目录:
~/refer_code/speech-demo/rest-api-asr/python/audio/
~/my_code/video2txt

grep_and_wget.sh

#!/xhdz/bash# source activate py35for url in $(cat ./data/videourl.txt | grep -o "http.*mp4")dowget -P ./data/video/ -nc $urlpython test.py $url# https://blog.csdn.net/watfe/article/details/80284242file="./data/audio/yo.txt"if [ -f "$file" ]; then echo -e "nn"$url | cat - "$file" >> result.txtfirm ./data/audio/*#breakdone

main.py

# -*- coding: utf-8 -*-"""Created on Sun Mar 17 09:12:27 2019@author: ddm"""from pydub import AudioSegmentimport sysimport osfrom pydub.silence import split_on_silencefrom aip import AipSpeech#百度验证部分APP_ID = '19276173'API_KEY = 'Se9UYG8D9LBauEQ3QwvX4zmG'SECRET_KEY = '3uZGWr2sISeOnsGKKHsccWAb6VzIuRCt'client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)video_name = sys.argv[1].split('/')[-1]#视频转音频AudioSegment.from_file('./data/video/'+video_name).export('./data/audio/test.wav', format='wav')#读取音频 预处理sound=AudioSegment.from_wav('./data/audio/test.wav')sound=sound.set_frame_rate(16000)sound=sound.set_channels(1)#切割音频pieces=split_on_silence(sound,min_silence_len=700,silence_thresh=-70)#silence_thresh=-32silent = AudioSegment.silent(duration=1000)#将音频转换为wavdef gotwave(audio): new = AudioSegment.empty() for inx,val in enumerate(audio): new=val+silent new.export('./data/audio/%d.wav' % inx,format='wav') #毫秒换算 根据需要只到分def ms2s(ms): mspart=ms%1000 mspart=str(mspart).zfill(3) spart=(ms//1000)%60 spart=str(spart).zfill(2) mpart=(ms//1000)//60 mpart=str(mpart).zfill(2) #srt的时间格式 stype="00:"+mpart+":"+spart+","+mspart return stype#读取切割后的文件def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read()#语音识别def audio2text(wavsample): rejson=client.asr(wavsample, 'wav', 16000, {'dev_pid': 1537,}) if (rejson['err_no']==0): result=rejson['result'][0] else: result="erro"+str(rejson['err_no']) return result #输出字幕def text2str(inx,text): strtext=str(inx)+'n --> n'+text+'n'+'n' return strtext#读写文件def strtxt(text): with open('./data/audio/yo.txt','a', encoding='utf-8') as fp: fp.write(text) fp.close() #mainif __name__ == '__main__': gotwave(pieces) for inx,val in enumerate(pieces): wav=get_file_content('./data/audio/%d.wav' % inx) text=audio2text(wav) #text2=text2str(inx,text) strtxt(text) print(str(round((inx/len(pieces))*100))+'%')

https://zhang0peter.com/2020/02/03/free-vedio-to-text-and-audio-to-text/
https://jianwai.netease.com/index/0 网易
https://www.jianshu.com/p/190ba2af8046 百度
百度官方代码示例 speech-demo
阿里接口API
https://help.aliyun.com/document_detail/90727.html?spm=a2c4g.11186623.6.581.49e854dbSNPIa1
https://www.cnblogs.com/ghq120/p/9063287.html

开源 https://cloud.tencent.com/developer/news/407877

视频转音频
利用pydub和baidu语音api实现自动添加字幕 pydub的中文文档
https://blog.csdn.net/lly1122334/article/details/90283655
http://www.360doc.com/content/19/0812/12/360939_854405435.shtml
https://cloud.tencent.com/developer/article/1555802

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。