This service provides a comprehensive solution for managing jobs and handling file transfers securely. It allows you to easily create and manage jobs, ensuring that all your multimedia and configuration files are processed reliably.
A Python client for interacting with the Voice Harbor API. This client handles job creation, file uploads, and result downloads through secure signed URLs. It supports audio file formats.
The client is designed to provide an end-to-end solution for managing voice processing jobs with the Voice Harbor API, offering both ease of use as a CLI tool and flexibility for integration into larger Python projects.
Job Management: Create new jobs and retrieve job details.
File Parsing & Validation: Automatically scans an input directory and filters files by supported formats (.wav, .mp3, …).
Secure File Uploads: Uses signed URLs to securely upload files via HTTP PUT requests.
Job Submission: Generates a YAML job file with all job parameters and uploads it securely.
Polling & Result Downloading: Downloads both processed files and their corresponding JSON metadata concurrently.
Logging & Error Handling: Provides a CLI with customizable options for API URL, authorization token, input/output directories, timeout settings, agents, and more.
Command-Line Interface (CLI): Offers detailed logging of operations and robust error management for easier troubleshooting.
List total global usage generated by all developer tokens.
Copy
BASE_URL = "https://voiceharbor.ai"for token_metadata in usage_tokens: jobs_metadata = VoiceHarborClient.get_jobs(BASE_URL, token_metadata['usage_token']) for job_metadata in jobs_metadata: print (VoiceHarborClient.get_job_content(BASE_URL, usage_token, job_metadata['job_id']))
The output is a JSON response represented as a dictionary with the following fields:
Copy
id: A unique integer identifier for the audio record.job_id: A unique string representing the job associated with the audio file.file_name: The name of the audio file.audio_duration: The duration of the audio file in seconds.created_at: An ISO 8601 timestamp indicating when the audio file was created.
BASE_URL = "https://voiceharbor.ai"usage_token = "TOKEN"# Create a new job on the server via the class method.# Create a new job immediately.job_id = VoiceHarborClient.create_job(BASE_URL, usage_token)print(f"Job created with ID: {job_id}")# Initialize the client with the new job_id and input directory.client = VoiceHarborClient( base_url=BASE_URL, job_id=job_id, token=AUTH_TOKEN, inputs_dir="./inputs")# Build job parameters (e.g., list of agents and any other details).job_params = { "agents": ["health-generic"], "files": [] # The submit_files method will append uploaded file names.}# Upload input files.job_params = client.submit_files(job_params)# Immediately submit the job file (YAML)job_file = client.submit_job(job_params)print(f"Job file submitted: {job_file}")# Wait for and download the processed results.downloaded_results = client.download_results(output_dir="./results")print("Downloaded results:", downloaded_results)
BASE_URL = "https://voiceharbor.ai"usage_token = "TOKEN"# Create a new job.job_id = VoiceHarborClient.create_job(BASE_URL, usage_token)print(f"Job created with ID: {job_id}")# Initialize the client with the new job_id.client = VoiceHarborClient( base_url=BASE_URL, job_id=job_id, token=AUTH_TOKEN, inputs_dir="./inputs")# Upload input files without submitting the job file immediately.job_params = { "agents": ["health-generic"], "files": []}job_params = client.submit_files(job_params)# Store the job parameters locally for later submission.job_params_file = f"{job_id}_job_params.json"with open(job_params_file, "w") as f: json.dump(job_params, f)print(f"Job parameters stored for later submission: {job_params_file}")
Simulate a delay (e.g., waiting until tomorrow to submit the job file).
Copy
# Later, load the stored job parameters and submit the job file.with open(job_params_file, "r") as f: delayed_job_params = json.load(f)job_file = client.submit_job(delayed_job_params)print(f"Delayed job file submitted: {job_file}")# Download the results when processing is complete.downloaded_results = client.download_results(output_dir="./results")print("Downloaded results:", downloaded_results)
In this scenario, you create and submit a job as usual. The job file (a YAML file named using the job_id) is saved locally. Then, at a later time (for example, the next day), you reinitialize your client using the same job_id and trigger the download of results.Step 1: Job Creation and Submission (Today).
Run the following script to create a job, upload input files, and submit the job file. This script also stores the job parameters locally (optionally) and writes the YAML file (named with the job_id) which can be used later to trigger the download.
Copy
BASE_URL = "https://voiceharbor.ai"usage_token = "TOKEN"# Create a new job.job_id = VoiceHarborClient.create_job(BASE_URL, usage_token)logger.info(f"Job created with ID: {job_id}")# Initialize the client with the new job_id and input directory.client = VoiceHarborClient( base_url=BASE_URL, job_id=job_id, token=AUTH_TOKEN, inputs_dir="./inputs" # Directory containing files to be uploaded.)# Build job parameters. For example, specify which agents to use.job_params = { "agents": ["health-generic"], "files": [] # The submit_files method will append the names of uploaded files.}# Upload input files.job_params = client.submit_files(job_params)# Submit the job file (this writes a YAML file named as {job_id}.yaml).job_file = client.submit_job(job_params)logger.info(f"Job file submitted and saved locally as: {job_file}") # <--- JOB_FILE_PATH
Step 2: Scheduled Download (Tomorrow)When you’re ready to download the results—say, tomorrow—you can run a separate script that reinitializes the client with the known job_id (from the YAML file name) and then calls the download function to retrieve the processed results.
Copy
BASE_URL = "https://voiceharbor.ai"usage_token = "TOKEN"# Use a existing job_id.JOB_ID = "<job_id>" # <--- JOB_ID # Reinitialize the client with the same job_id (inputs_dir is not required for download).client = VoiceHarborClient( base_url=BASE_URL, job_id=JOB_ID, token=AUTH_TOKEN, inputs_dir="" # No need for input files when only downloading results.)# Download the processed results, pass the yaml file created during last step.downloaded_results = client.download_results(output_dir="./results", yaml=job_file)logger.info(f"Downloaded results for job {JOB_ID}: {downloaded_results}")