Requirements
As best practice, it is recommended to set up your environment variables. Create a.env file in your project root and add the following:
Usage
Install the package vianpm.
Ready to Get Started?
Check out the Valence package on NPM →
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Get our SDK up and running in your Javascript environment
.env file in your project root and add the following:
VALENCE_API_KEY=your_api_key # Required: Your Valence API key
VALENCE_DISCRETE_URL=https://discrete-api-url # Optional: Discrete audio endpoint
VALENCE_ASYNCH_URL=https://asynch-api-url # Optional: Asynch audio endpoint
VALENCE_LOG_LEVEL=info # Optional: debug, info, warn, error
npm.
npm install valenceai
import { validateConfig } from 'valenceai';
try {
validateConfig();
console.log('Configuration is valid!');
} catch (error) {
console.error('Configuration error:', error.message);
}
import { ValenceClient } from 'valenceai';
client = new ValenceClient(
None, // API key (or use VALENCE_API_KEY env var)
5*1024*1024, // Size of each upload chunk for asynch audio
5 // Number of retry attempts
)
import { ValenceClient } from 'valenceai';
try {
const client = new ValenceClient();
const result = await client.discrete.emotions('YOUR_FILE.wav');
console.log('Emotion detected:', result);
} catch (error) {
console.error('Error:', error.message);
}
import { ValenceClient } from 'valenceai';
try {
const client = new ValenceClient();
// Upload the audio file
const requestId = await client.asynch.upload('YOUR_FILE.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);
}
import { ValenceClient } from 'valenceai';
// 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
);
