The lil’bots platform comes with ElevenLabs access built in. You can use the ElevenLabs API to build bots that can generate human-like speech from text.

ElevenLabs provides provides the leading text-to-speech API for generating human-like speech from text. You can use the ElevenLabs API to generate speech from text, customize the voice, and more.

Using the ElevenLabs API

You can use the following endpoints in the ElevenLabs API:

  • /v1/text-to-speech - generate speech from text docs
  • /v1/voices - list the available voices docs

Currently, custom voices are not supported in the lil’bots platform. You can use the default voice for generating speech. You can see a list of available voices by making a request to the /v1/voices or by visiting the ElevenLabs API Reference.

Using the ElevenLabs API - JavaScript Runtime

Here’s a simple example of a bot that uses the ElevenLabs API to generate speech from text:


export async function main(inputs, params, accounts) {
	let text = inputs?.text ?? "Hello, World!"
	
	let fileName = `./speech.mp3`
	let response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/zBRstRiKO1kURcfe1n81?output_format=mp3_44100_128`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			"text": text,
			"model": "eleven_turbo_v2"
		})
	})
	console.log(`Generation Response - ${response.status}`)
	if (response.status == 200 && response.body) {
		const f = await Deno.open(fileName, { create: true, write: true });
		await response.body.pipeTo(f.writable)
	} else {
		console.warn(await response.text())
	}

	return {
		title: "Generated Audio",
		file: fileName
	}
}