Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Sequence Models/Week 1/Jazz improvisation with LSTM/__pycache__/midi.cpython-36.pyc
Views: 13383
3 ��Z � @ sP d Z ddlZddlZddlZddlZddlZdZdZdZdZ dZ dZdZd d � Z dZejjeee e � ejjjd� ejZej� Z�y�g ZxBejd �D ]4\ZZZx(ejed�D ]Zejejj ee�� q�W q�W �x:eD �]0Z!ejj"ejj#e!��d Z$e$d Z%ej&ee edee d�Z'e(de$ d � e e!� g Z)x$ejjj*� �rRe)je'j+e �� �q0W e'j,� e'j-� ej&e%d�Z.e.j/e � e.j0ej1e�� e.j2e� e(de% � e.j3dj e)�� e.j-� er�ej4de% d e5e� d e5e � d e5e� d e$ d � er�ej6e%� q�W ej7� W n4 e8k �rJ ejjj9d� ejjj:� e;�Y nX dS )z� File: midi.py Author: Addy771 Description: A script which converts MIDI files to WAV and optionally to MP3 using ffmpeg. Works by playing each file and using the stereo mix device to record at the same time � NTiD� � i � � c C sN yt jjj| � W n* t jk r< td| t j� f � d S X t jjj� d S )NzCouldn't play %s! (%s))�pygame�mixer�music�load�error�print� get_error�play)� music_file� r �)/home/jovyan/work/Week 1/DeepJazz/midi.py� play_music s r � g �?z./z*.midz.wav)�format�channels�rate�inputZinput_device_index�frames_per_bufferzPlaying z.mid �wbzSaving � z ffmpeg -i z -y -f mp3 -ab zk -ac z -ar z -vn z.mp3i� i����)<�__doc__�pyaudio�waver �fnmatch�osZdo_ffmpeg_convertZdo_wav_cleanup�sample_rater �bufferZmp3_bitrateZinput_devicer �bitsizer �initr � set_volume�paInt16r �PyAudioZaudio�matches�walk�root�dirnames� filenames�filter�filename�append�path�joinZsong�splitext�basename� file_nameZnew_file�open�streamr �frames�get_busy�readZstop_stream�closeZ wave_file�setnchannels�setsampwidth�get_sample_size�setframerate�writeframes�system�str�remove� terminate�KeyboardInterrupt�fadeout�stop� SystemExitr r r r �<module> sd >