|
15 | 15 | # Get sound info example |
16 | 16 | print("Sound info:") |
17 | 17 | print("-----------") |
18 | | -sound = freesound_client.get_sound(96541) |
| 18 | +sound = freesound_client.get_sound(6) |
19 | 19 | print("Getting sound:", sound.name) |
20 | 20 | print("Url:", sound.url) |
21 | 21 | print("Description:", sound.description) |
|
26 | 26 | print("Sound info specifying some request parameters:") |
27 | 27 | print("-----------") |
28 | 28 | sound = freesound_client.get_sound( |
29 | | - 96541, fields="id,name,username,duration,analysis", descriptors="lowlevel.spectral_centroid", normalized=1 |
30 | | -) |
| 29 | + 6, fields="id,name,username,duration,spectral_centroid") |
31 | 30 | print("Getting sound:", sound.name) |
32 | 31 | print("Username:", sound.username) |
33 | 32 | print("Duration:", str(sound.duration), "(s)") |
34 | | -print("Spectral centroid:",) |
35 | | -print(sound.analysis.lowlevel.spectral_centroid.as_dict()) |
| 33 | +print("Spectral centroid:",str(sound.spectral_centroid), "(Hz)") |
36 | 34 | print() |
37 | 35 |
|
38 | 36 | # Get sound analysis example |
39 | 37 | print("Get analysis:") |
40 | 38 | print("-------------") |
41 | 39 | analysis = sound.get_analysis() |
42 | | - |
43 | | -mfcc = analysis.lowlevel.mfcc.mean |
| 40 | +mfcc = analysis.mfcc |
44 | 41 | print("Mfccs:", mfcc) |
45 | 42 | # you can also get the original json (this applies to any FreesoundObject): |
46 | 43 | print(analysis.as_dict()) |
47 | 44 | print() |
48 | 45 |
|
49 | | -# Get sound analysis example specifying some request parameters |
50 | | -print("Get analysis with specific normalized descriptor:") |
51 | | -print("-------------") |
52 | | -analysis = sound.get_analysis(descriptors="lowlevel.spectral_centroid.mean", normalized=1) |
53 | | -spectral_centroid_mean = analysis.lowlevel.spectral_centroid.mean |
54 | | -print("Normalized mean of spectral centroid:", spectral_centroid_mean) |
55 | | -print() |
56 | | - |
57 | 46 | # Get similar sounds example |
58 | 47 | print("Similar sounds: ") |
59 | 48 | print("---------------") |
|
62 | 51 | print("\t-", similar_sound.name, "by", similar_sound.username) |
63 | 52 | print() |
64 | 53 |
|
65 | | -# Get similar sounds example specifying some request parameters |
66 | | -print("Similar sounds specifying some request parameters:") |
67 | | -print("---------------") |
68 | | -results_pager = sound.get_similar( |
69 | | - page_size=10, fields="name,username", descriptors_filter="lowlevel.pitch.mean:[110 TO 180]" |
70 | | -) |
71 | | -for similar_sound in results_pager: |
72 | | - print("\t-", similar_sound.name, "by", similar_sound.username) |
73 | | -print() |
74 | | - |
75 | 54 | # Search Example |
76 | 55 | print("Searching for 'violoncello':") |
77 | 56 | print("----------------------------") |
78 | | -results_pager = freesound_client.text_search( |
| 57 | +results_pager = freesound_client.search( |
79 | 58 | query="violoncello", |
80 | 59 | filter="tag:tenuto duration:[1.0 TO 15.0]", |
81 | 60 | sort="rating_desc", |
|
91 | 70 | print("\t-", sound.name, "by", sound.username) |
92 | 71 | print() |
93 | 72 |
|
94 | | -# Content based search example |
95 | | -print("Content based search:") |
| 73 | +# Search all sounds that match some audio descriptor filter |
| 74 | +print("Filter by audio descriptors:") |
96 | 75 | print("---------------------") |
97 | | -results_pager = freesound_client.content_based_search( |
98 | | - descriptors_filter="lowlevel.pitch.var:[* TO 20]", |
99 | | - target='lowlevel.pitch_salience.mean:1.0 lowlevel.pitch.mean:440' |
| 76 | +results_pager = freesound_client.search( |
| 77 | + filter="spectral_centroid:[1000 TO 2000] AND pitch:[200 TO 300]", |
| 78 | + fields="name,username,spectral_centroid,pitch", |
100 | 79 | ) |
101 | 80 |
|
102 | 81 | print("Num results:", results_pager.count) |
103 | 82 | for sound in results_pager: |
104 | | - print("\t-", sound.name, "by", sound.username) |
| 83 | + print("\t-", sound.name, "by", sound.username, "with spectral centroid of", sound.spectral_centroid, "Hz and pitch of", sound.pitch, "Hz") |
105 | 84 | print() |
106 | 85 |
|
| 86 | +# We can use the search endpoint for a similarity search which also filters results |
| 87 | +print("Searching for similar sounds and filtering by a descriptor value:") |
| 88 | +print("---------------") |
| 89 | +results_pager = freesound_client.search( |
| 90 | + page_size=10, fields="name,username", similar_to=6, filter="pitch:[110 TO 180]" |
| 91 | +) |
| 92 | +for similar_sound in results_pager: |
| 93 | + print("\t-", similar_sound.name, "by", similar_sound.username) |
| 94 | +print() |
| 95 | + |
| 96 | +# Find sounds simialar to a target vector extracted from an existing sound which might not be in Freesound |
| 97 | +# Note that "similarity_space" must match with the similarity space used to extract the target vector |
| 98 | +print("Searching for sounds similar to a target vector:") |
| 99 | +print("---------------") |
| 100 | +target_vector = [0.84835537,-0.06019006,0.35139768,-0.01221892,-0.23172645,-0.03798686,-0.03869437,0.02199453,-0.10143687,-0.03342770,0.05464298,-0.02654354,0.05424048,0.04912830,0.01449411,-0.02995046,0.04584143,0.03731462,0.06914231,-0.00702387,-0.02202889,0.01644059,-0.00153376,0.11042101,0.05432773,0.05736105,-0.03779107,-0.00909068,-0.08996461,-0.04300615,0.05610843,0.02214170,-0.02155820,0.05158299,-0.00717155,-0.04345755,-0.00519616,0.02887811,-0.02205723,0.01658933,0.02485796,-0.06228176,0.03574570,-0.04556302,-0.00497004,0.00300936,-0.01974736,-0.01391953,-0.02898939,0.01041939,-0.02836645,0.00853050,-0.03129587,0.00454572,0.00898315,-0.01371797,-0.00918297,-0.01049032,0.02800968,-0.04248178,0.02648444,-0.01034762,0.02105908,-0.01137279,0.02845560,-0.04284714,0.00797986,0.00973879,-0.00850114,-0.01093731,-0.00629640,-0.01862817,0.00829806,0.01137537,0.02601988,0.03015542,-0.01091145,0.00547907,-0.00426657,0.01001693,0.00793383,0.00082211,-0.02848534,-0.00823537,0.01392606,-0.02012341,-0.00788319,0.02797560,-0.01470957,-0.01917517,-0.01177181,0.00952904,-0.00223396,-0.01586017,-0.00566903,0.01150901,-0.00361810,-0.00257769,-0.01509761,0.00552032] |
| 101 | +results_pager = freesound_client.search( |
| 102 | + page_size=10, fields="name,username", similar_to=target_vector, similarity_space="freesound_classic" |
| 103 | +) |
| 104 | +for similar_sound in results_pager: |
| 105 | + print("\t-", similar_sound.name, "by", similar_sound.username) |
| 106 | +print() |
| 107 | + |
| 108 | + |
107 | 109 | # Getting sounds from a user example |
108 | 110 | print("User sounds:") |
109 | 111 | print("-----------") |
|
126 | 128 | user = freesound_client.get_user("Headphaze") |
127 | 129 | print("User name:", user.username) |
128 | 130 | results_pager = user.get_sounds( |
129 | | - page_size=10, fields="name,username,samplerate,duration,analysis", descriptors="rhythm.bpm" |
| 131 | + page_size=10, fields="name,username,samplerate,duration" |
130 | 132 | ) |
131 | 133 |
|
132 | 134 | print("Num results:", results_pager.count) |
|
167 | 169 | pack = freesound_client.get_pack(3524) |
168 | 170 | print("Pack name:", pack.name) |
169 | 171 | results_pager = pack.get_sounds( |
170 | | - page_size=5, fields="id,name,username,duration,analysis", descriptors="lowlevel.spectral_flatness_db" |
| 172 | + page_size=5, fields="id,name,username,duration,spectral_flatness" |
171 | 173 | ) |
172 | 174 | print("Num results:", results_pager.count) |
173 | 175 | print("\t----- PAGE 1 -----") |
|
181 | 183 | ) |
182 | 184 | print( |
183 | 185 | sound.duration, |
184 | | - "s and a mean spectral flatness of", |
| 186 | + "s and a spectral flatness of", |
185 | 187 | ) |
186 | | - print(sound.analysis.lowlevel.spectral_flatness_db.mean) |
| 188 | + print(sound.spectral_flatness) |
187 | 189 | print("\t----- PAGE 2 -----") |
188 | 190 | results_pager = results_pager.next_page() |
189 | 191 | for sound in results_pager: |
|
196 | 198 | ) |
197 | 199 | print( |
198 | 200 | sound.duration, |
199 | | - "s and a mean spectral flatness of", |
| 201 | + "s and a spectral flatness of", |
200 | 202 | ) |
201 | | - print(sound.analysis.lowlevel.spectral_flatness_db.mean) |
| 203 | + print(sound.spectral_flatness) |
202 | 204 | print() |
0 commit comments