Discussions

Ask a Question
Back to All

Creating a talk using uploaded audio and image from our account

I want to use the following api:

POST <https://api.d-id.com/talks> | Create a talk

Request  
Response

{  
    "source_url": "<https://myhost.com/image.jpg">,  
    "script": {  
        "type": "audio",  
        "audio_url": "<https://path.to/audio.mp3">  
    }  
}

I am using this code to upload an audio file

import dotenv from 'dotenv';
import fs from 'fs';

dotenv.config();

const didApiKey = process.env.D_ID_API_KEY;
const audioURL = 'https://api.d-id.com/audios';

export const uploadAudio = async (audio) => {

	const formData = new FormData();
	formData.append('audio', audio, 'audio.mpeg');

	try {
		const response = await fetch(audioURL, {
			method: 'POST',
			headers: {
				'accept': 'application/json',
				'authorization': 'Basic ' + didApiKey,
			},
			body: formData
		});

		const data = await response.json();

		console.log("\x1b[46m\x1b[30m%s\x1b[0m", "This is the data from the DID API: ", data)
		return data;

	} catch (error) {
		console.error('Error fetching data:', error);
	}
}

It gives me back this response:

{
  url: 's3://d-id-audios-prod...',
  id: 'fQfFnUUyrLwfFnP2zPRyg',
  duration: 15.960813,
  moderation_metadata: {}
}

Questions

  1. Can I use the url and or id from the audios api as the audio url for the talks endpoint?

  2.         "audio_url": "<https://path.to/audio.mp3">  
    
    
  1. We have a bunch of presented images in our D-ID account. Is there a way to pass the ID of an image already in our account or I need to upload this via the https://api.d-id.com/images API as well?