Answers for "generate video from text python"

0

convert video to text python

import urllib2
import speech_recognition as sr
import subprocess
import os

url = 'https://cdn.fbsbx.com/v/t59.3654-21/15720510_10211855778255994_5430581267814940672_n.mp4/audioclip-1484407992000-3392.mp4?oh=a78286aa96c9dea29e5d07854194801c&oe=587C3833'
mp4file = urllib2.urlopen(url)

with open("test.mp4", "wb") as handle:
    handle.write(mp4file.read())

cmdline = ['avconv',
           '-i',
           'test.mp4',
           '-vn',
           '-f',
           'wav',
           'test.wav']
subprocess.call(cmdline)

r = sr.Recognizer()
with sr.AudioFile('test.wav') as source:
    audio = r.record(source)

command = r.recognize_google(audio)
print command

os.remove("test.mp4")
os.remove("test.wav")
Posted by: Guest on February-09-2021
0

Create video from images python

import os 
import cv2  
from PIL import Image  
  
print(os.getcwd())  
  
os.chdir("C:\Python\Geekfolder2")   
path = "C:\Python\Geekfolder2"
  
mean_height = 0
mean_width = 0
  
num_of_images = len(os.listdir('.')) 
  
for file in os.listdir('.'): 
    im = Image.open(os.path.join(path, file)) 
    width, height = im.size 
    mean_width += width 
    mean_height += height 
    
  
mean_width = int(mean_width / num_of_images) 
mean_height = int(mean_height / num_of_images) 
  
  
for file in os.listdir('.'): 
    if file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith("png"): 
        
        im = Image.open(os.path.join(path, file))  
   
        
        width, height = im.size    
        print(width, height) 
  
        
        imResize = im.resize((mean_width, mean_height), Image.ANTIALIAS)  
        imResize.save( file, 'JPEG', quality = 95) 
        
        print(im.filename.split('\')[-1], " is resized")  
  
  
def generate_video(): 
    image_folder = '.'
    video_name = 'mygeneratedvideo.avi'
    os.chdir("C:\Python\Geekfolder2") 
      
    images = [img for img in os.listdir(image_folder) 
              if img.endswith(".jpg") or
                 img.endswith(".jpeg") or
                 img.endswith("png")] 
     
    
    
    print(images)  
  
    frame = cv2.imread(os.path.join(image_folder, images[0])) 
  
    
    
    height, width, layers = frame.shape   
  
    video = cv2.VideoWriter(video_name, 0, 1, (width, height))  
  
    
    for image in images:  
        video.write(cv2.imread(os.path.join(image_folder, image)))  
      
    
    cv2.destroyAllWindows()  
    video.release()  
  
  
generate_video()
Posted by: Guest on September-11-2021

Code answers related to "generate video from text python"

Python Answers by Framework

Browse Popular Code Answers by Language