npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

valence-sdk

v0.3.0

Published

**valence-sdk-js** is a Node.js SDK for interacting with the [Valence Vibrations](https://valencevibrations.com) Emotion Detection API. It provides full support for uploading short and long audio files to retrieve their emotional signatures.

Readme

🎧 Valence SDK for Emotion Detection (JavaScript)

valence-sdk is a Node.js SDK for interacting with the Valence Vibrations Emotion Detection API. It provides full support for uploading discrete and async audio files to retrieve their emotional signatures.

✨ Features

  • 🎯 Discrete audio processing - Single API call for short audio files
  • 🔄 Async audio processing - Multipart streaming for long audio files
  • 🎭 Emotion models - Choose between 4-emotion or 7-emotion detection models
  • ⚙️ Environment configuration - Built-in support for .env configuration
  • 📊 Enhanced logging - Configurable log levels with timestamps
  • 🛡️ Robust error handling - Comprehensive validation and error recovery
  • TypeScript ready - Full JSDoc documentation for all functions
  • 🧪 100% tested - Comprehensive test suite with 95%+ coverage
  • 🔒 Security focused - Input validation and secure error handling

📦 Installation

npm install valence-sdk

🔧 Configuration

Create a .env file in your project root:

VALENCE_API_KEY=your_api_key                    # Required: Your Valence API key
VALENCE_DISCRETE_URL=https://discrete-api-url   # Optional: Discrete audio endpoint
VALENCE_ASYNC_URL=https://async-api-url         # Optional: Async audio endpoint  
VALENCE_LOG_LEVEL=info                          # Optional: debug, info, warn, error

Configuration Validation

import { validateConfig } from 'valence-sdk';

try {
  validateConfig();
  console.log('Configuration is valid!');
} catch (error) {
  console.error('Configuration error:', error.message);
}

🚀 Usage

Discrete Audio (Short Files)

import { ValenceClient } from 'valence-sdk';

try {
  const client = new ValenceClient();
  const result = await client.discrete.emotions('audio.wav', '7emotions');
  console.log('Emotions detected:', result);
} catch (error) {
  console.error('Error:', error.message);
}

Async Audio (Long Files)

import { ValenceClient } from 'valence-sdk';

try {
  const client = new ValenceClient();
  
  // Upload the audio file
  const requestId = await client.asynch.upload('long_audio.wav');
  console.log('Upload complete. Request ID:', requestId);
  
  // Get emotions from uploaded audio
  const emotions = await client.asynch.emotions(requestId);
  console.log('Emotions detected:', emotions);
} catch (error) {
  console.error('Error:', error.message);
}

Advanced Usage

import { ValenceClient } from 'valence-sdk';

// Custom client configuration
const client = new ValenceClient(
  2 * 1024 * 1024,  // 2MB parts
  5                  // 5 retry attempts
);

// Upload with custom configuration
const requestId = await client.asynch.upload('huge_file.wav');

// Custom polling with more attempts and shorter intervals
const emotions = await client.asynch.emotions(
  requestId,
  50,    // 50 polling attempts
  3      // 3 second intervals
);

🎛️ API Reference

new ValenceClient(partSize?, maxRetries?)

Creates a new Valence client with nested discrete and asynch clients.

Parameters:

  • partSize (number, optional): Size of each part in bytes for async uploads (default: 5MB)
  • maxRetries (number, optional): Maximum retry attempts for async uploads (default: 3)

Returns: ValenceClient instance with discrete and asynch properties

client.discrete.emotions(filePath, model?)

Predicts emotions for discrete (short) audio files using a single API call.

Parameters:

  • filePath (string): Path to the audio file
  • model (string, optional): "4emotions" or "7emotions" (default: "4emotions")

Returns: Promise<Object> - Emotion prediction results

Throws: Error if file doesn't exist, API key missing, or request fails

client.asynch.upload(filePath)

Uploads async (long) audio files using multipart upload for processing.

Parameters:

  • filePath (string): Path to the audio file

Returns: Promise<string> - Request ID for tracking the upload

Throws: Error if file doesn't exist, API key missing, or upload fails

client.asynch.emotions(requestId, maxAttempts?, intervalSeconds?)

Retrieves emotion prediction results for async audio processing.

Parameters:

  • requestId (string): Request ID from client.asynch.upload
  • maxAttempts (number, optional): Maximum polling attempts (default: 20, range: 1-100)
  • intervalSeconds (number, optional): Polling interval in seconds (default: 5, range: 1-60)

Returns: Promise<Object> - Emotion prediction results

Throws: Error if requestId is invalid or prediction times out

validateConfig()

Validates the current SDK configuration.

Throws: Error if required configuration is missing or invalid

🧪 Examples

Run the included examples:

# Install dependencies
npm install

# Run discrete audio example
npm run example:discrete

# Run async audio example  
npm run example:async

# Or run directly
node examples/uploadShort.js
node examples/uploadLong.js

🛠 Development

Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Watch mode for development
npm run test:watch

Building and Publishing

# Validate configuration and run tests
npm test

# Publish to npm
npm login
npm publish --access public

🚀 What's New in v0.3.0

Major Changes

  • 🏗️ Unified Client Architecture - Single ValenceClient with nested discrete and asynch clients
  • 🔄 API Restructure: predictDiscreteAudioEmotion()client.discrete.emotions()
  • 🔄 API Restructure: uploadAsyncAudio()client.asynch.upload()
  • 🔄 API Restructure: getEmotions()client.asynch.emotions()
  • 📦 Single Import: import { ValenceClient } from 'valence-sdk'

Benefits

  • Perfect API Symmetry - Identical structure to Python SDK
  • 🎯 Intuitive Organization - Related methods grouped together
  • 🔄 Consistent Naming - Same method names across Python and JavaScript
  • 📚 Enhanced Documentation - Updated examples and migration guide
  • 🧪 Maintained Quality - All existing functionality preserved

See CHANGELOG.md for complete details and migration guide.

🤝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes with tests
  4. Ensure all tests pass: npm test
  5. Submit a pull request

🆘 Support

📜 License

ISC License © 2025 Valence Vibrations