Exemple #1
0
        public SoundFingerprinter(IModelService modelService, string loadFromPath, string debugDirectoryPath)
        {
            SetDebugPath(debugDirectoryPath);

            // if the modelService was passed, use it
            if (modelService != null)
            {
                this.modelService = modelService;
            }
            else
            {
                //  ... otherwise use the loadFromPath
                this.modelService = GetSQLiteDatabaseService(loadFromPath);
            }

            // and set the rest of the services
            this.audioService = new FindSimilarAudioService();

            var fingerprintConfig = new ShortSamplesFingerprintConfiguration();

            this.spectrumService = new FindSimilarSpectrumService(
                fingerprintConfig.SpectrogramConfig,
                new LogUtility()
                );

            this.fingerprintService = new FindSimilarFingerprintService(
                spectrumService,
                new LocalitySensitiveHashingAlgorithm(new MinHashService(new MaxEntropyPermutations()), new HashConverter()),
                new StandardHaarWaveletDecomposition(),
                new FastFingerprintDescriptor()
                );

            this.fingerprintCommandBuilder = new FingerprintCommandBuilder(fingerprintService);
        }
Exemple #2
0
        public bool StoreAudioFileFingerprintsInStorageForLaterRetrieval(string pathToAudioFile, TrackData track, Verbosity verbosity)
        {
            if (track == null)
            {
                return(false);
            }

            var fingerprintConfig = new ShortSamplesFingerprintConfiguration();

            // set verbosity
            fingerprintConfig.SpectrogramConfig.Verbosity = verbosity;

            try
            {
                // create hashed fingerprints
                var hashedFingerprints = fingerprintCommandBuilder
                                         .BuildFingerprintCommand()
                                         .From(pathToAudioFile)
                                         .WithFingerprintConfig(fingerprintConfig)
                                         .UsingServices(audioService)
                                         .Hash()
                                         .Result;

                if (hashedFingerprints.Count > 0)
                {
                    lock (_lockObj)
                    {
                        // store track metadata in the datasource
                        var trackReference = modelService.InsertTrack(track);

                        // store hashes in the database for later retrieval
                        modelService.InsertHashDataForTrack(hashedFingerprints, trackReference);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (System.Exception e)
            {
                // Log
                Log.Information(e.Message);
                return(false);
            }
        }