File size: 1,498 Bytes
8ad5dc2
 
e199a32
8ad5dc2
9504de3
7d76a49
 
 
 
 
 
 
 
 
e199a32
7d76a49
8ad5dc2
7d76a49
8ad5dc2
 
1d5e8ba
 
 
 
b5509c2
1d5e8ba
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
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)