├── README.md ├── out.wav └── videotoword.py /README.md: -------------------------------------------------------------------------------- 1 | # video-to-word 2 | python+百度语音识别API, 读取视频文件,将视频中的语音转换成文字输出 3 | -------------------------------------------------------------------------------- /out.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuchengle/video-to-word/693bf2b1ceadadcfb85abbc901b5abca922791dd/out.wav -------------------------------------------------------------------------------- /videotoword.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | from moviepy.editor import VideoFileClip 5 | from aip import AipSpeech 6 | 7 | 8 | # # 视频转音频 9 | 10 | video_file = 'https://v2.addnewer.com/media/2020/08/1596606940740.mp4' 11 | audio_file = '/data/jupyter/yucl/videotoword/out.wav' 12 | video = VideoFileClip(video_file) 13 | video.audio.write_audiofile(audio_file,ffmpeg_params=['-ar','16000','-ac','1']) 14 | 15 | 16 | # # 音频转文本 17 | 18 | ''' 19 | 百度语音识别:https://console.bce.baidu.com/ai/?_=1597039403602#/ai/speech/overview/index 20 | ''' 21 | #从百度AI开放平台创建应用处获取 22 | APP_ID = '***' 23 | API_KEY = '***' 24 | SECRET_KEY = '***' 25 | 26 | client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) 27 | 28 | # 读取文件 29 | def get_file_content(audio_file): 30 | with open(audio_file, 'rb') as fp: 31 | return fp.read() 32 | 33 | # 识别本地文件 34 | def get_text(): 35 | result = client.asr(get_file_content(audio_file), 'wav', 16000, {'dev_pid': 1537,}) 36 | #print(result) 37 | text = result['result'][0] 38 | return text 39 | 40 | res = get_text() 41 | print (res) 42 | 43 | '''紫熨斗全新的文体验波色因欧莱雅集团专利成本协同,玻尿酸生锈,石伟有一段话拽文,抬头纹和法令纹,眼部的全脸细纹,青森淡季功能鸭子熨斗。''' 44 | --------------------------------------------------------------------------------