Skip to content

Instantly share code, notes, and snippets.

@jdt1
Last active July 11, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdt1/3871cfca6941e6d48569bc61b754d861 to your computer and use it in GitHub Desktop.
Save jdt1/3871cfca6941e6d48569bc61b754d861 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from subprocess import check_call\n",
"from datetime import datetime\n",
"import itertools"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"audiofile = \"[INSERT DIRECTORY HERE]\\distant_clip.wav\"\n",
"lame = \"[INSERT DIRECTORY HERE]\\lame.exe\""
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = 1000 # number of times to do the conversion\n",
"name, ext = audiofile.split('.')\n",
"filenames = [audiofile] + [name + str(i) + '_times' + '.mp3' for i in range(1, n+1)]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def convert_lame(filename, outfilename):\n",
" check_call([\n",
" lame,\n",
" '-V5', # avg. 130 kbps\n",
" filename,\n",
" outfilename\n",
" ],\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# see https://docs.python.org/3/library/itertools.html\n",
"# for more cool tricks\n",
"def pairwise(iterable):\n",
" \"s -> (s0,s1), (s1,s2), (s2, s3), ...\"\n",
" a, b = itertools.tee(iterable)\n",
" next(b, None)\n",
" return zip(a, b)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done. (0:05:29.945580)\n"
]
}
],
"source": [
"start = datetime.now()\n",
"for infile, outfile in pairwise(filenames):\n",
" convert_lame(infile, outfile)\n",
"end = datetime.now()\n",
"print('Done. (' + str(end - start) + ')')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment