| Crates.io | freesound-rs |
| lib.rs | freesound-rs |
| version | 0.2.0 |
| created_at | 2025-03-23 15:00:12.639737+00 |
| updated_at | 2025-03-23 15:00:12.639737+00 |
| description | A Rust client for the Freesound API to search and get sounds only |
| homepage | https://github.com/taophp/freesound-rs |
| repository | https://github.com/taophp/freesound-rs |
| max_upload_size | |
| id | 1602741 |
| size | 77,903 |
A Rust client library for the Freesound API.
Note: this is a side project, so I should only implement search and get sound endpoints for now. But contributions are welcome!
Add this to your Cargo.toml:
cargo add freesound-rs
use freesound_rs::{FreesoundClient, SearchQueryBuilder, SortOption};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize client with your API key
let client = FreesoundClient::new("YOUR_API_KEY".to_string(), None);
Ok(())
}
// Simple search
let query = SearchQueryBuilder::new()
.query("piano")
.build();
let results = client.search(&query).await?;
println!("Found {} piano sounds", results.count);
// Advanced search with filters and sorting
let query = SearchQueryBuilder::new()
.query("music")
.filter("tag:guitar duration:[1 TO 10]") // Guitar sounds between 1 and 10 seconds
.sort(SortOption::RatingDesc) // Best rated first
.page(1)
.page_size(15)
.fields(["id", "name", "tags", "previews"]) // Only return these fields
.build();
let results = client.search(&query).await?;
// Process search results
for sound in results.results {
println!("Found sound: {} (#{}) by {}", sound.name, sound.id, sound.username);
}
// Get basic sound information
let sound = client.get_sound(1234, None, None).await?;
println!("Sound: {} by {}", sound.name, sound.username);
println!("Duration: {}s", sound.duration);
println!("License: {}", sound.license);
// Get sound with audio analysis descriptors
let sound = client
.get_sound(
1234,
Some(&["lowlevel.mfcc", "rhythm.bpm"]),
Some(true) // normalize values
)
.await?;
// Access preview URLs
if let Some(previews) = sound.previews {
println!("HQ MP3 preview: {}", previews.preview_hq_mp3);
println!("HQ OGG preview: {}", previews.preview_hq_ogg);
}
Obtain a Freesound API key:
Create an .env file with your key and run the tests:
cp env.sample .env
# edit `.env` to add your FreeSound API key
cargo test
This project is licensed under the GNU LGPL License - see the LICENSE file for details.