fastperson / utils.py
kwmr's picture
upload
b5509c2
from pytube import YouTube
from scipy.signal import resample
from firebase_admin import firestore
def log_firestore(db, local_id="000000", action="test", url=""):
data = {
"local_id": local_id,
"timestamp": firestore.SERVER_TIMESTAMP,
"action": action,
"url": url
}
doc_ref = db.collection("exp.1").document()
doc_ref.set(data)
def get_youtube(video_url, local_id, db):
# YouTubeの動画をダウンロード
log_firestore(db, local_id=str(local_id), action='DV', url=str(video_url))
print("Start download video")
yt = YouTube(video_url)
video_length = yt.length
if video_length > 180:
video_url = "https://www.youtube.com/watch?v=QghjaS0WQQU"
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)