Spaces:
Sleeping
Sleeping
File size: 1,714 Bytes
8ad5dc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import copy
import subprocess
from pytube import YouTube
from scipy.signal import resample
import numpy as np
import pytsmod as tsm
from moviepy.audio.AudioClip import AudioArrayClip
from moviepy.editor import *
from moviepy.video.fx.speedx import speedx
from sentence_transformers import SentenceTransformer, util
from transformers import pipeline, BertTokenizer, BertForNextSentencePrediction
import torch
import whisper
subprocess.run(['apt-get', '-y', 'install', 'imagemagick'])
transcriber = whisper.load_model("medium")
sentence_transformer = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
tokenizer = BertTokenizer.from_pretrained("bert-base-cased")
next_sentence_predict = BertForNextSentencePrediction.from_pretrained("bert-base-cased").eval()
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
def get_youtube(video_url):
# YouTubeの動画をダウンロード
print("Start download video")
yt = YouTube(video_url)
abs_video_path = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename='download.mp4', output_path='movies/')
print("Success download video")
print(abs_video_path)
return abs_video_path
def two_chnnel_to_one_channel(sample):
# 音声を2チャンネルから1チャンネルに変換
left_channel = sample[:, 0]
right_channel = sample[:, 1]
mono_sample = (left_channel + right_channel) / 2
return mono_sample
def convert_sample_rate(data, original_sr, target_sr):
# 音声データのサンプリング周波数を変更
target_length = int(len(data) * target_sr / original_sr)
return resample(data, target_length) |