openvino-genai-node
Version:
OpenVINO™ GenAI pipelines for using from Node.js environment
66 lines • 2.69 kB
JavaScript
// Copyright (C) 2023-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
import util from "node:util";
import { Text2SpeechPipeline as Text2SpeechPipelineWrapper } from "../addon.js";
import { Text2SpeechDecodedResults } from "../decodedResults.js";
/**
* Pipeline for text-to-speech synthesis.
*
* Converts text input into audio waveform tensors.
* Use the factory method `PipelineFactory.Text2SpeechPipeline()` to create and
* initialize an instance.
*/
export class Text2SpeechPipeline {
/**
* Construct a Text2Speech pipeline from a folder containing model IRs.
* @param modelPath - Path to the folder with model IRs.
* @param device - Inference device (e.g. "CPU", "GPU").
* @param properties - Device and pipeline properties.
*/
constructor(modelPath, device, properties = {}) {
this.pipeline = null;
this.modelPath = modelPath;
this.device = device;
this.properties = properties;
}
/**
* Load the pipeline. Must be called once before generate().
*/
async init() {
const pipeline = new Text2SpeechPipelineWrapper();
const initPromise = util.promisify(pipeline.init.bind(pipeline));
await initPromise(this.modelPath, this.device, this.properties);
this.pipeline = pipeline;
}
/**
* Generate audio from a single text or batch of texts.
* @param input - Text string or array of text strings to synthesize.
* @param options - Optional speaker embedding and generation config.
* @returns Decoded results with audio waveform tensors and perf metrics.
*/
async generate(input, options = {}) {
if (!this.pipeline)
throw new Error("Text2SpeechPipeline is not initialized");
const { speakerEmbedding, generationConfig } = options;
const generatePromise = util.promisify(this.pipeline.generate.bind(this.pipeline));
const res = await generatePromise(input, speakerEmbedding, generationConfig !== null && generationConfig !== void 0 ? generationConfig : {});
return new Text2SpeechDecodedResults(res.speeches, res.perfMetrics);
}
/**
* Get current speech generation config.
*/
getGenerationConfig() {
if (!this.pipeline)
throw new Error("Text2SpeechPipeline is not initialized");
return this.pipeline.getGenerationConfig();
}
/**
* Update speech generation config.
*/
setGenerationConfig(config) {
if (!this.pipeline)
throw new Error("Text2SpeechPipeline is not initialized");
this.pipeline.setGenerationConfig(config);
}
}
//# sourceMappingURL=text2SpeechPipeline.js.map