@lesjoursfr/gcp-tts
v1.0.1
Published
Wrapper around the Google Cloud TTS module.
Downloads
126
Readme
gcp-tts
Generate audio files from text file using GCP.
Presentation
This module convert text to sound using the Google Cloud Text-to-Speech service.
import { Languages, synthesizeTextWithGCP, Voices } from "@lesjoursfr/gcp-tts";
let result = await synthesizeTextWithGCP(
"Alice, assise auprès de sa sœur sur le gazon, …",
{
projectId: "gcp-project-id",
clientOptions: { credentials: credentials },
bucketId: "gcp-bucket-id",
},
{
language: Languages.fr_FR,
voice: Voices.fr_FR_Neural2_A,
audioEncoding: "LINEAR16",
},
{ folder: "/an/absolute/path", filename: "filename-without-extension" }
);
You can also convert the generated file to WEBA and/or M4A. You need to have ffmpeg installed on your system to do that.
import {
Codecs,
Languages,
synthesizeTextWithGCP,
Voices,
} from "@lesjoursfr/gcp-tts";
let result = await synthesizeTextWithGCP(
"Alice, assise auprès de sa sœur sur le gazon, …",
{
projectId: "gcp-project-id",
clientOptions: { credentials: credentials },
bucketId: "gcp-bucket-id",
},
{
language: Languages.fr_FR,
voice: Voices.fr_FR_Neural2_A,
audioEncoding: "LINEAR16",
},
{ folder: "/an/absolute/path", filename: "filename-without-extension" },
[
{ codec: Codecs.weba, options: { audioBitrate: 256 } },
{ codec: Codecs.m4a, options: { audioBitrate: 256 } },
]
);
The return object is:
type SynthesizeResult = {
sourceFile: string; // File path of the original generated file
extraEncodes: Array<string>; // Array of file paths converted by ffmpeg
};