<jupyter_start><jupyter_text>論文  https://arxiv.org/abs/2112.04685  GitHub  https://github.com/haoheliu/2021-ISMIR-MSS-Challenge-CWS-PResUNet  環境セットアップ  GPU確認<jupyter_code>!nvidia-smi<jupyter_output><empty_output><jupyter_text>GitHubからコード取得<jupyter_code>%cd /content

!git clone https://github.com/haoheliu/2021-ISMIR-MSS-Challenge-CWS-PResUNet.git<jupyter_output><empty_output><jupyter_text>ライブラリのインストール<jupyter_code>%cd /content/2021-ISMIR-MSS-Challenge-CWS-PResUNet

!pip install --upgrade gdown

! pip3 install -r requirements.txt
# ModuleNotFoundError: No module named 'torchtext.legacy' 回避のため torchtextはバージョン固定
! pip3 install torchtext==0.8.1 demucs==3.0.1<jupyter_output><empty_output><jupyter_text>Vocal抽出(テスト音源)<jupyter_code>%cd /content/2021-ISMIR-MSS-Challenge-CWS-PResUNet

!python3 main.py -i example/test -o example/results -s vocals other --cuda<jupyter_output><empty_output><jupyter_text>抽出結果再生<jupyter_code>import IPython.display as ipd
ipd.Audio("example/test/xuemaojiao.wav", rate=44100)
ipd.Audio("example/results/xuemaojiao/vocals.wav", rate=44100)<jupyter_output><empty_output><jupyter_text>Vocal抽出(Youtube)  動画のセットアップ<jupyter_code>!pip install yt-dlp moviepy 
from yt_dlp import YoutubeDL

from moviepy.video.fx.resize import resize
from moviepy.editor import VideoFileClip, AudioFileClip, ImageSequenceClip, CompositeAudioClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
video_url = 'https://www.youtube.com/watch?v=Qd01-6xVSHk' #@param {type:"string"}

#@markdown 動画の切り抜き範囲(秒)を指定してください。\
#@markdown 30秒以上の場合OOM発生の可能性が高いため注意
start_sec =  57#@param {type:"integer"}
end_sec =  69#@param {type:"integer"}

(start_pt, end_pt) = (start_sec, end_sec)<jupyter_output><empty_output><jupyter_text>動画取得<jupyter_code>!mkdir -p /content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results


download_resolution = 360
full_video_path = '/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/full_video.mp4'
input_clip_path = '/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/input_clip.mp4'
input_audio_path = '/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/input_clip.wav'

# 動画ダウンロード
ydl_opts = {'format': f'best[height<={download_resolution}]', 'overwrites': True, 'outtmpl': full_video_path}
with YoutubeDL(ydl_opts) as ydl:
    ydl.download([video_url])<jupyter_output><empty_output><jupyter_text>指定区間切り抜き<jupyter_code># extract the relevant subclip:
with VideoFileClip(full_video_path) as video:
    subclip = video.subclip(start_pt, end_pt)
    subclip.write_videofile(input_clip_path)<jupyter_output><empty_output><jupyter_text>切り抜き箇所(0~5秒)再生<jupyter_code>clip = VideoFileClip(input_clip_path)

if 5 < (end_pt-start_pt):
  clip = clip.subclip(0, 5)
  
clip = resize(clip, height=420)
clip.ipython_display()<jupyter_output><empty_output><jupyter_text>audioファイル取得<jupyter_code>clip = VideoFileClip(input_clip_path)
clip.audio.write_audiofile(input_audio_path, codec='pcm_s16le')

ipd.Audio(input_audio_path, rate=44100)<jupyter_output><empty_output><jupyter_text>Vocal抽出<jupyter_code>!python3 main.py -i {input_audio_path} -o /content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results -s vocals other --cuda<jupyter_output><empty_output><jupyter_text>Vocal<jupyter_code>ipd.Audio('/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results/input_clip/vocals.wav', rate=44100)<jupyter_output><empty_output><jupyter_text>Vocal以外<jupyter_code>ipd.Audio('/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results/input_clip/other.wav', rate=44100)<jupyter_output><empty_output><jupyter_text>Vocalのみの動画を作成<jupyter_code>videoclip = VideoFileClip(input_clip_path)
audioclip = AudioFileClip("/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results/input_clip/vocals.wav")

new_audioclip = CompositeAudioClip([audioclip])
videoclip.audio = new_audioclip
videoclip.write_videofile("/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results/input_clip/vocals.mp4")
clip = VideoFileClip('/content/2021-ISMIR-MSS-Challenge-CWS-PResUNet/videos/results/input_clip/vocals.mp4')
  
clip = resize(clip, height=420)
clip.ipython_display()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13155339805825242, 'fraction_numerical': 0.03131067961165049, 'mean_word_length': 8.239910313901346, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 57, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '136008', 'license': 'MIT', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1808, 'n_words': 165, 'path': 'CWS_PResUNet_demo.ipynb', 'repo_name': 'kaz12tech/ai_demos', 'size': '4120'}