Matxa Multiaccent Endpoint

Input parameters

Parameter
Description
Type
Options/Range
Recommended Values

text

Input text to be converted to speech

string

Any text input

N/A

voice

Speaker name for voice output

string

8 speakers available

N/A

accent

Selected dialect for voice output

string

balear, central, nord-occidental, valencia

N/A

temperature

Controls sampling variance during inference. Lower values yield higher quality but less variability

float

0.2 to 0.67

0.2 to 0.67

length_scale

Related to speech speed. Higher values make the speech slower, while lower values make it faster

float

0.75 to 0.9

0.75 to 0.9

List of associated accents and speakers (female voice and male voice) available. Each integer value is associated with one of the speakers you see in the list below:

Accent
Name
speaker_id

Balear

Quim

0

Balear

Olga

1

Central

Grau

2

Central

Elia

3

Nord-occidental

Pere

4

Nord-occidental

Emma

5

Valencia

Lluc

6

Valencia

Gina

7

Code examples

Python

example.py
import requests

API_URL = "https://p1b28cv1e843tih1.eu-west-1.aws.endpoints.huggingface.cloud/api/tts"
headers = {
   "Authorization": "Bearer <hf_token>",
}

def query(text):
   data = {"text": text, "voice": "quim", "accent": "balear"}
   return requests.post(API_URL, headers=headers, json=data)

response = query("Bon dia")
with open("output.wav", "wb") as f:
   f.write(response.content)

Curl

One effective way is to create a temporary JSON archive to pass text and input parameters for inference.

printf '%s' '{
  "text": "Ara caldrà veure què passa amb aquestes investigacions judicials, si segueixen endavant i se l'\''acaba jutjant, o si es desestimen d'\''acord amb la immunitat que tindrà un altre cop com a president del país.",
  "voice": “quim”,
  “accent”: “balear”,
  "type": "text"
}' > data.json

curl -X POST https://p1b28cv1e843tih1.eu-west-1.aws.endpoints.huggingface.cloud/api/tts -H "Content-Type: application/json" -H "Authorization: Bearer <hf_token>"  -d @data.json | play -t wav -

Javascript (Nodejs)

Executed with Nodejs. Install NPM (Node Package Manager) and with NPM install fetch-node library.

const fetch = require("node-fetch");
const fs = require("fs");

// Define the API URL and headers
const API_URL = "https://p1b28cv1e843tih1.eu-west-1.aws.endpoints.huggingface.cloud/api/tts";
const headers = {
    "Authorization": "Bearer <hf_token>",
    "Content-Type": "application/json"
};

// Function to send the request
async function query(text) {
    const data = {
        text: text,
        accent: “balear”,
        voice: “olga”
    };

    try {
        // POST request
        const response = await fetch(API_URL, {
            method: "POST",
            headers: headers,
            body: JSON.stringify(data)
        });

        // Check the response
        if (!response.ok) {
            throw new Error(`Error: ${response.status} ${response.statusText}`);
        }

        // Convert the response to a buffer
        const buffer = await response.buffer();

        // Write the buffer to an output file
        fs.writeFile("output.wav", buffer, (err) => {
            if (err) {
                console.error("Error saving the file:", err);
            } else {
                console.log("File saved as output.wav");
            }
        });

        
    } catch (error) {
        console.error("Error making request:", error);
    }
}

// Your query
query("Bon dia.");

Last updated