204 lines
4.7 KiB
Plaintext
204 lines
4.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sppysound.database import AudioDatabase, Matcher\n",
|
|
"import matching_config"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"source_dir = \"./ExampleDatabase\"\n",
|
|
"target_dir = \"./ExampleTarget\"\n",
|
|
"output_dir = \"./ExampleOutput\"\n",
|
|
"analysis_list = [\"rms\", \"f0\"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Load source and target databases for matching..."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"source_database = AudioDatabase(source_dir, analysis_list=analysis_list, config=matching_config)\n",
|
|
"source_database.load_database(reanalyse=False)\n",
|
|
"target_database = AudioDatabase(target_dir, analysis_list=analysis_list, config=matching_config)\n",
|
|
"target_database.load_database(reanalyse=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"An output database must also be defined. This is to store matching results and synthesis results generated later.\n",
|
|
"Note that an analysis list was not defined for this as it will not be analysed"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"output_database = AudioDatabase(output_dir, config=matching_config)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The database must still be loaded to check for previous HDF5 files to use for results"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"output_database.load_database(reanalyse=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"A matcher object is then created using the loaded databases, ready to perform matching. The rematch argument can be set to discard any previously found matches from pre-existing HDF5 files, otherwise previously found matches will cause the program to terminate for their preservation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"matcher = Matcher(\n",
|
|
" source_database,\n",
|
|
" target_database,\n",
|
|
" output_db=output_database,\n",
|
|
" config=matching_config,\n",
|
|
" rematch=True\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The matching is then run using the brute force matcher method. Other methods are not currently available.\n",
|
|
"\n",
|
|
"Warnings may be produced during this process. These will be silenced in a future revision but do not affect results."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"matcher.match(\n",
|
|
" matcher.brute_force_matcher,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The output database will now contain a HDF5 file containing matching data for the two databases. This can be used to synthesize results."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The matching_config file for this demo is:\n",
|
|
"~~~python\n",
|
|
"rms = {\n",
|
|
" \"window_size\": 100,\n",
|
|
" \"overlap\": 2,\n",
|
|
"}\n",
|
|
"\n",
|
|
"analysis_dict = {\n",
|
|
" \"f0\": \"log2_median\",\n",
|
|
" \"rms\": \"mean\"\n",
|
|
"}\n",
|
|
"\n",
|
|
"matcher_weightings = {\n",
|
|
" \"f0\" : 1.,\n",
|
|
" \"rms\": 1.\n",
|
|
"}\n",
|
|
"\n",
|
|
"analysis = {\n",
|
|
" \"reanalyse\": False\n",
|
|
"}\n",
|
|
"\n",
|
|
"matcher = {\n",
|
|
" \"rematch\": False,\n",
|
|
" \"grain_size\": 100,\n",
|
|
" \"overlap\": 2,\n",
|
|
" # Defines the number of matches to keep for synthesis.\n",
|
|
" \"match_quantity\": 20\n",
|
|
"}\n",
|
|
"\n",
|
|
"output_file = {\n",
|
|
" \"samplerate\": 44100,\n",
|
|
" \"format\": 131075,\n",
|
|
" \"channels\": 1\n",
|
|
"}\n",
|
|
"~~~"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 2",
|
|
"language": "python",
|
|
"name": "python2"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|