Audio management Documentation

Audio Management API

The Nuxera Audio Management API allows you to download, delete, and manage audio files stored on the Nuxera platform. These endpoints provide control over the audio files used in transcription and dictation processes.

Endpoints Overview

EndpointMethodDescription
/api/downloadGETDownload audio files stored on the server
/api/deleteDELETEDelete a specific audio file
/api/delete-allDELETEDelete all audio files

Download Audio

Endpoint: /api/download

Method: GET

Description: Download an audio file associated with a specific doctor.

Request Parameters

ParameterTypeLocationRequiredDescription
doctorNamestringQueryYesName of the doctor associated with the audio file

Response

On success, the API returns the audio file as a downloadable attachment.

Headers:

  • Content-Type: audio/wav or audio/flac (depending on the stored format)
  • Content-Disposition: attachment; filename="audio-doctorName.wav"

Error Response (400 Bad Request)

{
  "error": "Doctor name is required"
}

Error Response (404 Not Found)

{
  "error": "No audio file found for this doctor"
}

Example Usage

cURL

curl -X GET 'https://api.nuxera.ai/api/download?doctorName=Dr.%20Smith' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  --output downloaded_audio.wav

JavaScript

// Function to download an audio file
async function downloadAudio(token, doctorName, filename) {
  try {
    const response = await fetch(
      `https://api.nuxera.ai/api/download?doctorName=${encodeURIComponent(
        doctorName
      )}`,
      {
        method: 'GET',
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );

    if (!response.ok) {
      if (response.status === 404) {
        throw new Error('No audio file found for this doctor');
      }
      throw new Error('Failed to download audio file');
    }

    // Create a blob from the response
    const blob = await response.blob();

    // Create a download link and trigger download
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    a.download = filename || `audio-${doctorName}.wav`;
    document.body.appendChild(a);
    a.click();

    // Clean up
    window.URL.revokeObjectURL(url);
    document.body.removeChild(a);
  } catch (error) {
    console.error('Download error:', error);
    throw error;
  }
}

// Example usage
document
  .getElementById('download-button')
  .addEventListener('click', async () => {
    const doctorName = document.getElementById('doctor-name').value;

    try {
      await downloadAudio(
        localStorage.getItem('authToken'),
        doctorName,
        `${doctorName}-recording.wav`
      );
      alert('Download successful!');
    } catch (error) {
      alert(`Error: ${error.message}`);
    }
  });

Python

import requests

def download_audio(token, doctor_name, output_path):
    """
    Download an audio file for a specific doctor

    Args:
        token (str): Authentication token
        doctor_name (str): Name of the doctor
        output_path (str): Path where the downloaded file will be saved

    Returns:
        bool: True if download was successful
    """
    url = f'https://api.nuxera.ai/api/download?doctorName={doctor_name}'

    headers = {
        'Authorization': f'Bearer {token}'
    }

    response = requests.get(url, headers=headers, stream=True)

    if response.status_code != 200:
        error_data = response.json()
        raise Exception(error_data.get('error', 'Failed to download audio'))

    # Save the file
    with open(output_path, 'wb') as f:
        for chunk in response.iter_content(chunk_size=8192):
            f.write(chunk)

    return True

# Example usage
try:
    token = "YOUR_AUTH_TOKEN"
    success = download_audio(
        token=token,
        doctor_name="Dr.Johnson",
        output_path="./downloaded_audio.wav"
    )

    if success:
        print("Audio file downloaded successfully")

except Exception as e:
    print(f"Error: {str(e)}")

Delete Audio

Endpoint: /api/delete

Method: DELETE

Description: Delete an audio file associated with a specific doctor.

Request Parameters

ParameterTypeLocationRequiredDescription
doctorNamestringQueryYesName of the doctor associated with the audio file

Response

Success Response (200 OK)

{
  "message": "File(s) deleted successfully."
}

Error Response (400 Bad Request)

{
  "error": "Doctor name is required."
}

Error Response (404 Not Found)

{
  "error": "No audio file found for this doctor."
}

Example Usage

cURL

curl -X DELETE 'https://api.nuxera.ai/api/delete?doctorName=Dr.%20Smith' \
  -H 'Authorization: Bearer YOUR_TOKEN'

JavaScript

// Function to delete an audio file
async function deleteAudio(token, doctorName) {
  try {
    const response = await fetch(
      `https://api.nuxera.ai/api/delete?doctorName=${encodeURIComponent(
        doctorName
      )}`,
      {
        method: 'DELETE',
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.error || 'Failed to delete audio file');
    }

    return await response.json();
  } catch (error) {
    console.error('Delete error:', error);
    throw error;
  }
}

// Example usage
document.getElementById('delete-button').addEventListener('click', async () => {
  const doctorName = document.getElementById('doctor-name').value;

  if (
    confirm(`Are you sure you want to delete the audio file for ${doctorName}?`)
  ) {
    try {
      const result = await deleteAudio(
        localStorage.getItem('authToken'),
        doctorName
      );
      alert(result.message);
    } catch (error) {
      alert(`Error: ${error.message}`);
    }
  }
});

Python

import requests

def delete_audio(token, doctor_name):
    """
    Delete an audio file for a specific doctor

    Args:
        token (str): Authentication token
        doctor_name (str): Name of the doctor

    Returns:
        dict: Server response
    """
    url = f'https://api.nuxera.ai/api/delete?doctorName={doctor_name}'

    headers = {
        'Authorization': f'Bearer {token}'
    }

    response = requests.delete(url, headers=headers)

    if response.status_code != 200:
        error_data = response.json()
        raise Exception(error_data.get('error', 'Failed to delete audio'))

    return response.json()

# Example usage
try:
    token = "YOUR_AUTH_TOKEN"
    result = delete_audio(
        token=token,
        doctor_name="Dr.Johnson"
    )

    print(result['message'])

except Exception as e:
    print(f"Error: {str(e)}")

Delete All Audio

Endpoint: /api/delete-all

Method: DELETE

Description: Delete all audio files stored on the server.

Response

Success Response (200 OK)

{
  "message": "All files deleted successfully."
}

Error Response (500 Internal Server Error)

{
  "error": "Failed to delete files."
}

Example Usage

cURL

curl -X DELETE 'https://api.nuxera.ai/api/delete-all' \
  -H 'Authorization: Bearer YOUR_TOKEN'

JavaScript

// Function to delete all audio files
async function deleteAllAudio(token) {
  try {
    const response = await fetch('https://api.nuxera.ai/api/delete-all', {
      method: 'DELETE',
      headers: {
        Authorization: `Bearer ${token}`,
      },
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.error || 'Failed to delete all audio files');
    }

    return await response.json();
  } catch (error) {
    console.error('Delete all error:', error);
    throw error;
  }
}

// Example usage
document
  .getElementById('delete-all-button')
  .addEventListener('click', async () => {
    if (
      confirm(
        'Are you sure you want to delete ALL audio files? This action cannot be undone!'
      )
    ) {
      try {
        const result = await deleteAllAudio(localStorage.getItem('authToken'));
        alert(result.message);
      } catch (error) {
        alert(`Error: ${error.message}`);
      }
    }
  });

Python

import requests

def delete_all_audio(token):
    """
    Delete all audio files on the server

    Args:
        token (str): Authentication token

    Returns:
        dict: Server response
    """
    url = 'https://api.nuxera.ai/api/delete-all'

    headers = {
        'Authorization': f'Bearer {token}'
    }

    response = requests.delete(url, headers=headers)

    if response.status_code != 200:
        error_data = response.json()
        raise Exception(error_data.get('error', 'Failed to delete all audio files'))

    return response.json()

# Example usage
try:
    token = "YOUR_AUTH_TOKEN"

    # Confirm before deleting all files
    confirmation = input("Are you sure you want to delete ALL audio files? (yes/no): ")

    if confirmation.lower() == 'yes':
        result = delete_all_audio(token=token)
        print(result['message'])
    else:
        print("Operation cancelled")

except Exception as e:
    print(f"Error: {str(e)}")

Best Practices

  1. Data Management

    • Regularly clean up audio files that are no longer needed
    • Download important audio files before deletion for backup purposes
    • Use descriptive doctor names to easily identify audio files
  2. Security Considerations

    • Implement proper access controls for delete operations
    • Keep audit logs of audio file deletions
    • Use secure storage for downloaded audio files
  3. Error Handling

    • Implement retry logic for download operations
    • Verify successful deletion before removing local references
    • Handle 404 errors appropriately when files may have already been deleted

Limitations

  • Audio files are only accessible by doctor name
  • Downloaded files maintain their original format (WAV or FLAC)
  • All deleted files are permanently removed and cannot be recovered

Next Steps

Continue to the Implementation Guides to learn about best practices for integrating Nuxera APIs into your healthcare applications.