Playback Calls
Making a Playback call with Dialvox.ai is simple. A Playback call is an automated call made to a specified phone number to deliver a text-to-speech message. This feature is particularly useful for sending verification codes or important notifications. Here's how you can initiate a Playback call by posting data to the Dialvox.ai API:
Prerequisites
Before making a Playback call, ensure that you have:
- A valid API key from Dialvox.ai.
- The recipient's correct phone number in international format.
- The text you want to convert to speech.
Making a Playback Call
To make a Playback call, you need to POST
the following JSON data to the Dialvox.ai API URL:
https://api.dialvox.ai/requests/play
{
"text": "This is an example text to be converted to audio via TTS",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
Replace YOUR_API_KEY
with your actual API key.
JSON Fields Explanation
text
: The message you want to be read to the recipient. It can be in any language supported by the API, but the language must match thelanguage
parameter.language
: The language code for the text-to-speech engine. For example, "en-US" stands for US English.phone_number
: The recipient's phone number in the international format, which includes the country code (e.g., "0055" for Brazil) followed by the phone number.api_key
: Your unique API key provided by Dialvox.ai that authenticates your requests.
Available Languages
Currently, dialvox accepts the following languages:
en-US
- English (United States)es-ES
- Spanish (Spain)de-DE
- German (Germany)pt-BR
- Portuguese (Brazil)en-IN
- English (India)fr-FR
- French (France)hi-IN
- Hindi (India)
Making the HTTP Request
You can use any HTTP client to make the POST
request. Here's are a few examples on how to make the requests
CURL on CMD
curl -X POST "https://api.dialvox.ai/requests/play" \
-H "Content-Type: application/json" \
-d '{
"text": "This is an example text to be converted to audio via TTS",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}'
JavaScript Axios
const axios = require('axios');
const data = {
text: "This is an example text to be converted to audio via TTS",
language: "en-US",
phone_number: "005535987654321",
api_key: "YOUR_API_KEY"
};
axios.post('https://api.dialvox.ai/request/play', data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
Python Requests
import requests
import json
data = {
"text": "This is an example text to be converted to audio via TTS",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
response = requests.post('https://api.dialvox.ai/request/play', json=data)
print(response)
Go native http
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
data := map[string]string{
"text": "This is an example text to be converted to audio via TTS",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY",
}
jsonData, err := json.Marshal(data)
if err != nil {
panic(err)
}
resp, err := http.Post("https://api.dialvox.ai/request/play", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
defer resp.Body.Close()
}
Flutter(Dart) http
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> makePlaybackCall() async {
final url = Uri.parse('https://api.dialvox.ai/request/play');
final headers = {'Content-Type': 'application/json'};
final body = jsonEncode({
'text': 'This is an example text to be converted to audio via TTS',
'language': 'en-US',
'phone_number': '005535987654321',
'api_key': 'YOUR_API_KEY'
});
try {
final response = await http.post(url, headers: headers, body: body);
if (response.statusCode == 200) {
print('Playback call successful: ${response.body}');
} else {
print('Playback call failed: ${response.body}');
}
} catch (e) {
print('Error occurred while making playback call: $e');
}
}
Java HttpClient
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class DialvoxApiExample {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"text": "This is an example text to be converted to audio via TTS",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dialvox.ai/request/play"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
client.sendAsync(request, BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Note: Always keep your API key secret. Do not expose it in publicly accessible areas such as GitHub, client-side code, and so forth.