Basic Usage
Core Functionality
Authenticate
The first step is to initialize the SDK client with the credentials that have been provided to you:
Note: If you are both a Search: Pex Registry and Search: Custom Database customer, each product will require a separate set of credentials.
# AUTHENTICATE CLIENT
client = pex.PexSearchClient("CLIENT_ID", "CLIENT_SECRET")
// AUTHENTICATE CLIENT
client, err := pex.NewPexSearchClient("clientID", "clientSecret")
if err != nil {
panic(err)
}
defer client.Close()
// AUTHENTICATE CLIENT
$client = new Pex\PexSearchClient(CLIENT_ID, CLIENT_SECRET);
// AUTHENTICATE CLIENT
let client = new pex.PexSearchClient(CLIENT_ID, CLIENT_SECRET)
await client.connect()
Note: There might be a slight delay the first time you authenticate as the SDK downloads and installs necessary updates
Generate Fingerprint
Before performing any searches you need to generate a fingerprint from a media file:
# CREATE AUDIO FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.AUDIO)
# CREATE MELODY FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.MELODY)
# CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.AUDIO)
# CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.MELODY)
// CREATE AUDIO FINGERPRINT FROM MEDIA FILE
ft, err := client.FingerprintFile(inputFile, pex.FingerprintTypeAudio)
if err != nil {
panic(err)
}
// CREATE MELODY FINGERPRINT FROM MEDIA FILE
ft, err := client.FingerprintFile(inputFile, pex.FingerprintTypeMelody)
if err != nil {
panic(err)
}
// CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft, err := client.FingerprintBuffer([]byte, pex.FingerprintTypeAudio)
if err != nil {
panic(err)
}
// CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft, err := client.FingerprintBuffer([]byte, pex.FingerprintTypeMelody)
if err != nil {
panic(err)
}
// CREATE AUDIO FINGERPRINT FROM MEDIA FILE
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Audio]);
// CREATE MELODY FINGERPRINT FROM MEDIA FILE
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Melody]);
// CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
$ft = $client->fingerprintBuffer([]byte, [Pex\FingerprintType::Audio]);
// CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
$ft = $client->fingerprintBuffer([]byte, [Pex\FingerprintType::Melody]);
// CREATE AUDIO FINGERPRINT FROM MEDIA FILE
let ft = await client.fingerprintFile("video.mp4", [pex.AUDIO])
// CREATE MELODY FINGERPRINT
let ft = await client.fingerprintFile("video.mp4", [pex.MELODY])
// CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
let ft = await client.fingerprintBuffer([]byte, [pex.AUDIO])
// CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
let ft = await client.fingerprintBuffer([]byte, [pex.MELODY])
Note: When creating audio fingerprints, the SDK uses a single CPU. For melody fingerprints, the SDK uses two CPUs, if available.
If you need to process larger volumes of files, running computations in parallel is recommended. This can significantly improve processing capacity.
For information on the difference between audio and melody fingerprints and the use cases they address, please see our FAQ page
Search Functionality
Initiate Search
Once the fingerprint has been generated, you are ready to initiate a search:
# BUILD REQUEST FOR "IDENTIFY MUSIC" SEARCH TYPE
req = pex.PexSearchRequest(fingerprint=ft, type=pex.PexSearchType.IDENTIFY_MUSIC)
# BUILD REQUEST FOR "FIND MATCHES" SEARCH TYPE
req = pex.PexSearchRequest(fingerprint=ft, type=pex.PexSearchType.FIND_MATCHES)
# START SEARCH
future = client.start_search(req)
// BUILD REQUEST FOR "IDENTIFY MUSIC" SEARCH TYPE
req := &pex.PexSearchRequest{
Fingerprint: ft,
Type: pex.IdentifyMusic,
}
// BUILD REQUEST FOR "FIND MATCHES" SEARCH TYPE
req := &pex.PexSearchRequest{
Fingerprint: ft,
Type: pex.FindMatches,
}
// START SEARCH
fut, err := client.StartSearch(req)
if err != nil {
panic(err)
}
// BUILD REQUEST FOR "IDENTIFY MUSIC" SEARCH TYPE
$req = new Pex\PexSearchRequest($ft, $type=Pex\PexSearchType::IdentifyMusic)
// BUILD REQUEST FOR "FIND MATCHES" SEARCH TYPE
$req = new Pex\PexSearchRequest($ft, $type=Pex\PexSearchType::FindMatches)
// START SEARCH
$fut = $client->startSearch($req);
// START SEARCH FOR "IDENTIFY MUSIC" SEARCH TYPE
let result = await client.startSearch({
"fingerprint": ft,
"type": pex.IDENTIFY_MUSIC,
})
// START SEARCH FOR "FIND MATCHES" SEARCH TYPE
let result = await client.startSearch({
"fingerprint": ft,
"type": pex.FIND_MATCHES,
})
Note: For an explanation of what each "search type" does, please see this page: Search Types.
If no search type is designated when building the request, the request will default to the "identify music" search type
Retrieve Search Results
Once a search is complete, you can retrieve the results of the search:
# RETRIEVE SEARCH RESULTS
result = future.get()
// RETRIEVE SEARCH RESULTS
res, err := fut.Get()
if err != nil {
panic(err)
}
// RETRIEVE SEARCH RESULTS
$res = $fut->get();
// THE STARTSEARCH FUNCTION DESCRIBED IN THE PREVIOUS SECTION WILL AUTOMATICALLY RETRIEVE THE RESULTS WHEN THE SEARCH IS COMPLETED
Interpret Search Results
To view details on what's contained in a search response, please see the following section: Search Response
Last updated