Matching a target sample to a databaseΒΆ

In [1]:
from sppysound.database import AudioDatabase, Matcher
import matching_config
In [2]:
source_dir = "./ExampleDatabase"
target_dir = "./ExampleTarget"
output_dir = "./ExampleOutput"
analysis_list = ["rms", "f0"]

Load source and target databases for matching...

In [3]:
source_database = AudioDatabase(
    source_dir,
    analysis_list=analysis_list,
    config=matching_config
)
source_database.load_database(reanalyse=True)
target_database = AudioDatabase(
    target_dir,
    analysis_list=analysis_list,
    config=matching_config
)
target_database.load_database(reanalyse=True)
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-3-9c41c481744c> in <module>()
      4     config=matching_config
      5 )
----> 6 source_database.load_database(reanalyse=True)
      7 target_database = AudioDatabase(
      8     target_dir,

/Users/samuelperry/PerryPerrySource/pysource/sppysound/src/sppysound/database.pyc in load_database(self, reanalyse)
    119             self.organize_audio(subdir_paths, symlink=self.config.database["symlink"])
    120 
--> 121         self.analyse_database(subdir_paths, reanalyse)
    122 
    123     def analyse_database(self, subdir_paths, reanalyse):

/Users/samuelperry/PerryPerrySource/pysource/sppysound/src/sppysound/database.pyc in analyse_database(self, subdir_paths, reanalyse)
    140                           "corrupted HDF5 file.\n Make sure this is the only "
    141                           "running instance and regenerate HDF5 if "
--> 142                           "neccesary.".format(datapath))
    143         self.analysed_audio = []
    144 

IOError: Unable to create/append to file: ./ExampleDatabase/data/analysis_data.hdf5
This may be due to another instance of this program running or a corrupted HDF5 file.
 Make sure this is the only running instance and regenerate HDF5 if neccesary.

An output database must also be defined. This is to store matching results and synthesis results generated later. Note that an analysis list was not defined for this as it will not be analysed

In [4]:
output_database = AudioDatabase(output_dir, config=matching_config)

The database must still be loaded to check for previous HDF5 files to use for results

In [5]:
output_database.load_database(reanalyse=False)

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.

In [6]:
matcher = Matcher(
    source_database,
    target_database,
    output_db=output_database,
    config=matching_config,
    rematch=True
)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-a85bd403c2df> in <module>()
      1 matcher = Matcher(
      2     source_database,
----> 3     target_database,
      4     output_db=output_database,
      5     config=matching_config,

NameError: name 'target_database' is not defined

The matching is then run using the brute force matcher method. Other methods are not currently available.

Warnings may be produced during this process. These will be silenced in a future revision but do not affect results.

In [7]:
matcher.match(
    matcher.kdtree_matcher,
)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-f0cece17161b> in <module>()
----> 1 matcher.match(
      2     matcher.kdtree_matcher,
      3 )

NameError: name 'matcher' is not defined

The output database will now contain a HDF5 file containing matching data for the two databases. This can be used to synthesize results.

The matching_config file for this demo is:

rms = {
    "window_size": 100,
    "overlap": 2,
}

analysis_dict = {
    "f0": "log2_median",
    "rms": "mean"
}

matcher_weightings = {
    "f0" : 1.,
    "rms": 1.
}

analysis = {
    "reanalyse": False
}

matcher = {
    "rematch": False,
    "grain_size": 100,
    "overlap": 2,
    # Defines the number of matches to keep for synthesis.
    "match_quantity": 20
}

output_file = {
    "samplerate": 44100,
    "format": 131075,
    "channels": 1
}