Initiation à Text to Speech
Le service IBM Watson® Text to Speech convertit le texte écrit en discours naturel pour offrir des fonctionnalités de synthèse vocale aux applications. Ce tutoriel basé sur curl peut vous aider à démarrer rapidement avec le service.
Les exemples vous montrent comment appeler les méthodes POST et GET /v1/synthesize du service pour demander un flux audio.
Le tutoriel utilise l'utilitaire de ligne de commande curl pour illustrer les appels d'API REST. Pour plus d'informations sur curl, voir Utilisation de curl avec des exemples Watson.
IBM Cloud Regardez la vidéo suivante pour un résumé visuel de la prise en main du service Text to Speech.
Avant de commencer
IBM Cloud
IBM Cloud
Ce tutoriel utilise une clé d'interface de programmation (API) pour l'authentification. En production, utilisez un jeton IAM. Pour plus d'informations, voir Authentification auprès d' IBM Cloud.
IBM Cloud Pak for Data
IBM Cloud Pak for Data
Le service Text to Speech doit être installé et configuré avant de commencer ce tutoriel. Pour plus d'informations, consultez Watson Services vocaux sur Cloud Pak for Data.
- Créez une instance du service à l'aide du client Web, de l'API ou de l'interface de ligne de commande. Pour plus d'informations sur la création d'une instance de service sur IBM Cloud Pak for Data, voir Création d'une instance de service pour les services vocaux d' Watson.
- Suivez les instructions de la rubrique Création d'une instance de services vocaux Watson pour obtenir un jeton Bearer pour l'instance. Ce tutoriel utilise un jeton Bearer pour s'authentifier auprès du service.
Synthèse du texte en anglais américain
La commande suivante utilise la méthode POST /v1/synthesize pour synthétiser les entrées en anglais américain en audio. La demande utilise la voix en-US_MichaelV3Voice. Elle produit de l'audio au format WAV.
Vous pouvez utiliser un navigateur ou d’autres outils pour lire les fichiers audio générés par les exemples de ce tutoriel. Pour plus d'informations, voir Lecture d'un fichier audio.
-
Exécutez la commande suivante pour synthétiser la chaîne « hello world ». La demande produit le fichier WAV
hello_world.wav.IBM Cloud
curl -X POST -u "apikey:{apikey}" \ --header "Content-Type: application/json" \ --header "Accept: audio/wav" \ --data "{\"text\":\"hello world\"}" \ --output hello_world.wav \ "{url}/v1/synthesize?voice=en-US_MichaelV3Voice"IBM Cloud Pak for Data IBM Software Hub
- Remplacez
{token}et{url}par l'identifiant d'accès et URL pour votre instance de service.
curl -X POST \ --header "Authorization: Bearer {token}" \ --header "Content-Type: application/json" \ --header "Accept: audio/wav" \ --data "{\"text\":\"hello world\"}" \ --output hello_world.wav \ "{url}/v1/synthesize?voice=en-US_MichaelV3Voice" - Remplacez
Utiliser une voix et un format audio différents
La commande suivante utilise à nouveau la méthode POST /v1/synthesize pour synthétiser les mêmes entrées en anglais américain. Mais cette demande utilise la voix en-US_AllisonV3Voice et demande explicitement l'audio
au format Ogg par défaut.
-
Exécutez la commande suivante pour synthétiser la chaîne « hello world » mais avec une voix différente. La demande génère le fichier Ogg
hello_world.ogg.IBM Cloud
curl -X POST -u "apikey:{apikey}" \ --header "Content-Type: application/json" \ --data "{\"text\":\"hello world\"}" \ --output hello_world.ogg \ "{url}/v1/synthesize?voice=en-US_AllisonV3Voice"IBM Cloud Pak for Data IBM Software Hub
- Remplacez
{token}et{url}par l'identifiant d'accès et URL pour votre instance de service.
curl -X POST \ --header "Authorization: Bearer {token}" \ --header "Content-Type: application/json" \ --header "Accept: audio/wav" \ --data "{\"text\":\"hello world\"}" \ --output hello_world.wav \ "{url}/v1/synthesize?voice=en-US_AllisonV3Voice" - Remplacez
Synthèse du texte en espagnol
La commande suivante utilise la méthode GET /v1/synthesize pour synthétiser l’entrée en espagnol dans un fichier audio. La méthode GET inclut trois paramètres de requête : accept pour spécifier le format
audio, text pour spécifier le texte d'entrée pour l'audio et voice pour spécifier une voix espagnole. Comme accept et text sont transmis en tant que paramètres de requête, la demande est
codée dans l'URL.
-
Exécutez la commande suivante pour synthétiser la chaîne "hola mundo" et générer un fichier WAV nommé
hola_mundo.wav.IBM Cloud
curl -X GET -u "apikey:{apikey}" \ --output hola_mundo.wav \ "{url}/v1/synthesize?accept=audio%2Fwav&text=hola%20mundo&voice=es-ES_EnriqueV3Voice"IBM Cloud Pak for Data IBM Software Hub
- Remplacez
{token}et{url}par l'identifiant d'accès et URL pour votre instance de service.
curl -X POST \ --header "Authorization: Bearer {token}" \ --output hola_mundo.wav \ "{url}/v1/synthesize?accept=audio%2Fwav&text=hola%20mundo&voice=es-ES_EnriqueV3Voice" - Remplacez
Etapes suivantes
- Pour essayer une application d'exemple qui accepte du texte et génère de la parole avec différentes voix, consultez la démo Text to Speech.
- Pour plus d'informations sur les interfaces et les fonctionnalités du service, voir Fonctionnalités du service.
- Pour plus d'informations sur toutes les méthodes des interfaces du service, consultez la référence API & SDK.