### Install @bestcodes/edge-tts Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Install the package using npm or bun. ```bash npm install @bestcodes/edge-tts # or bun add @bestcodes/edge-tts ``` -------------------------------- ### Write Audio to File Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/1.0.3 This example shows how to synthesize speech and save the audio output directly to a file. Ensure the output path is valid. ```javascript import { MsEdgeTTS, OUTPUT_FORMAT } from "msedge-tts"; (async () => { const tts = new MsEdgeTTS(); await tts.setMetadata( "en-US-AriaNeural", OUTPUT_FORMAT.WEBM_24KHZ_16BIT_MONO_OPUS ); const filePath = await tts.toFile("./example_audio.webm", "Hi, how are you?"); })(); ``` -------------------------------- ### Use Alternative HTTP Agent (SOCKS Proxy) Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/1.0.3 This example demonstrates how to configure the TTS client to use a custom HTTP agent, such as a SOCKS proxy. This is useful for network routing or security configurations. ```javascript import { SocksProxyAgent } from "socks-proxy-agent"; (async () => { const agent = new SocksProxyAgent( "socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com" ); const tts = new MsEdgeTTS(agent); await tts.setMetadata( "en-US-AriaNeural", OUTPUT_FORMAT.WEBM_24KHZ_16BIT_MONO_OPUS ); const filePath = await tts.toFile("./example_audio.webm", "Hi, how are you?"); })(); ``` -------------------------------- ### Generate Audio Buffer Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use generateSpeech to get an audio buffer from text. Specify the voice for generation. ```typescript import { generateSpeech } from "@bestcodes/edge-tts"; const audio = await generateSpeech({ text: "Hello, world!", voice: "en-US-EmmaMultilingualNeural", }); // Do something with the audio buffer ``` -------------------------------- ### Get Audio Buffer with streamSpeech Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Use streamSpeech to get an audio buffer from text. Specify the text and the desired voice. ```typescript import { streamSpeech } from "@bestcodes/edge-tts"; const audio = await streamSpeech({ text: "Hello, world!", voice: "en-US-EmmaMultilingualNeural", }); // Do something with the audio buffer ``` -------------------------------- ### Get All and Find Voices Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use getVoices to retrieve all available TTS voices and findVoices to filter them based on criteria like Gender or Locale. ```typescript import { getVoices, findVoices } from "@bestcodes/edge-tts"; // Get all voices const allVoices = await getVoices(); // Find specific voices const femaleVoices = await findVoices({ Gender: "Female" }); const englishVoices = await findVoices({ Locale: "en-US" }); ``` -------------------------------- ### generateSpeechWithSubtitlesToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Generates speech and corresponding SRT subtitles, saving both to specified file paths. ```APIDOC ## generateSpeechWithSubtitlesToFile ### Description Generates speech from the provided text and creates accompanying SRT subtitles. Both the audio and subtitles are saved to their respective file paths. ### Method `generateSpeechWithSubtitlesToFile(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **subtitlePath** (string) - Required - The path where the SRT subtitle file will be saved. - **outputPath** (string) - Optional - The path where the audio file will be saved. If not provided, audio is not saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "This text will have subtitles.", "subtitlePath": "./subtitles.srt" } ``` ### Response #### Success Response (200) - **audio** (Buffer) - The generated audio data (only if outputPath is provided). - **subtitles** (string) - The generated subtitle content. ``` -------------------------------- ### Stream Audio Directly to File with Progress Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use streamSpeechToFile to stream audio directly to a file and monitor the writing progress. ```typescript import { streamSpeechToFile } from "@bestcodes/edge-tts"; for await (const progress of streamSpeechToFile({ text: "Hello, world!", outputPath: "./output.mp3", })) { console.log( `Written: ${progress.bytesWritten} bytes (chunk: ${progress.chunkSize})`, ); } ``` -------------------------------- ### streamSpeechWithSubtitlesToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Streams audio and subtitle data in real-time, saving both to specified files. ```APIDOC ## streamSpeechWithSubtitlesToFile ### Description Streams both audio chunks and subtitle data in real-time. Audio is written to the `outputPath` and subtitles are updated in the `subtitlePath` as they are generated. This is useful for live captioning or synchronized media. ### Method `streamSpeechWithSubtitlesToFile(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **subtitlePath** (string) - Required - The path where the SRT subtitle file will be saved. - **outputPath** (string) - Optional - The path where the audio file will be saved. If not provided, audio is not saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "This text will have subtitles.", "subtitlePath": "./subtitles.srt" } ``` ### Response #### Success Response (200) An async iterator yielding chunks. Each chunk can be: - `{ type: 'audio', data: Buffer }`: Contains audio data. - `{ type: 'subtitles', subtitles: string }`: Contains the updated subtitle content. ``` -------------------------------- ### Write Audio to Stream Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/1.0.3 This snippet demonstrates how to synthesize speech and pipe the audio output to a readable stream. It's useful for real-time audio processing or playback. ```javascript import { MsEdgeTTS, OUTPUT_FORMAT } from "msedge-tts"; const tts = new MsEdgeTTS(); await tts.setMetadata( "en-IE-ConnorNeural", OUTPUT_FORMAT.WEBM_24KHZ_16BIT_MONO_OPUS ); const readable = tts.toStream("Hi, how are you?"); readable.on("data", (data) => { console.log("DATA RECEIVED", data); // raw audio file data }); readable.on("close", () => { console.log("STREAM CLOSED"); }); ``` -------------------------------- ### Save Audio to File with streamSpeechToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Use streamSpeechToFile to save the generated audio directly to a file. Provide the text and the output file path. ```typescript import { streamSpeechToFile } from "@bestcodes/edge-tts"; await streamSpeechToFile({ text: "Hello, world!", outputPath: "./output.mp3", }); ``` -------------------------------- ### Save Audio to File Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use generateSpeechToFile to save the generated speech directly to an MP3 file. ```typescript import { generateSpeechToFile } from "@bestcodes/edge-tts"; await generateSpeechToFile({ text: "Hello, world!", outputPath: "./output.mp3", }); ``` -------------------------------- ### Experimental_Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1?activeTab=code Provides a low-level API for direct communication and streaming of speech data and metadata. ```APIDOC ## Experimental_Raw.Communicate ### Description Provides a low-level API for direct communication and streaming of speech data and metadata. ### Method `new Experimental_Raw.Communicate(text: string, voice: string): CommunicateInstance` ### Parameters #### Path Parameters None #### Query Parameters None #### Constructor Parameters * **text** (string) - Required - The text to convert to speech. * **voice** (string) - Required - The voice to use for speech generation. ### Instance Methods #### stream() * **Description**: Streams audio data and word boundary metadata. * **Returns**: `AsyncIterable<{ type: "audio"; data: Buffer } | { type: "WordBoundary"; data: any }>` ### Request Example ```javascript import { Experimental_Raw } from "@bestcodes/edge-tts"; const communicate = new Experimental_Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) } else if (chunk.type === "WordBoundary") { // Word boundary metadata } } ``` ### Response #### Success Response (200) An async iterable yielding chunks of data. Each chunk can be either an audio chunk or word boundary metadata. ``` -------------------------------- ### streamSpeechToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Streams audio chunks directly to a file, providing real-time progress updates. ```APIDOC ## streamSpeechToFile ### Description Streams audio chunks directly to a specified output file and provides real-time progress updates on bytes written and chunk sizes. This is efficient for large audio files. ### Method `streamSpeechToFile(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **outputPath** (string) - Required - The path where the audio file will be saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "Hello, world!", "outputPath": "./output.mp3" } ``` ### Response #### Success Response (200) An async iterator yielding progress updates. Each progress update object contains: - **bytesWritten** (number) - The total number of bytes written to the file so far. - **chunkSize** (number) - The size of the current audio chunk processed. ``` -------------------------------- ### streamSpeechWithSubtitles Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependencies Streams speech audio and generates corresponding SRT subtitles, saving them to a specified file path. ```APIDOC ## streamSpeechWithSubtitles ### Description Streams speech audio and generates corresponding SRT subtitles, saving them to a specified file path. ### Method `streamSpeechWithSubtitles` ### Parameters #### Options - **text** (string) - Required - The text to convert to speech. - **subtitlePath** (string) - Required - The path where the SRT subtitle file will be saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```typescript import { streamSpeechWithSubtitles } from "@bestcodes/edge-tts"; const { audio, subtitles } = await streamSpeechWithSubtitles({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", }); ``` ### Response #### Success Response - **audio** (Buffer) - The audio data buffer. - **subtitles** (string) - The generated subtitles content. ``` -------------------------------- ### Generate Speech with Subtitles Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use generateSpeechWithSubtitlesToFile to create both an audio file and an SRT subtitle file. ```typescript import { generateSpeechWithSubtitlesToFile } from "@bestcodes/edge-tts"; const { audio, subtitles } = await generateSpeechWithSubtitlesToFile({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", }); ``` -------------------------------- ### Generate Audio with Subtitles using streamSpeechWithSubtitles Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Use streamSpeechWithSubtitles to generate both audio and SRT subtitles. Specify the text and the subtitle file path. ```typescript import { streamSpeechWithSubtitles } from "@bestcodes/edge-tts"; const { audio, subtitles } = await streamSpeechWithSubtitles({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", }); ``` -------------------------------- ### streamSpeechWithSubtitles Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=readme Generates audio and corresponding SRT subtitles from the provided text. ```APIDOC ## streamSpeechWithSubtitles ### Description Generates audio and corresponding SRT subtitles from the provided text. ### Method `streamSpeechWithSubtitles` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **subtitlePath** (string) - Required - The file path where the subtitles will be saved. - **voice** (string) - Optional - The voice to use (default: "en-US-EmmaMultilingualNeural"). - **rate** (string) - Optional - The speech rate (e.g., "+10%" or "-20%"). Default: "+0%". - **volume** (string) - Optional - The speech volume (e.g., "+50%" or "-10%"). Default: "+0%". - **pitch** (string) - Optional - The speech pitch (e.g., "+10Hz" or "-5Hz"). Default: "+0Hz". - **boundary** (string) - Optional - The word or sentence boundary type ("WordBoundary" or "SentenceBoundary"). - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds (default: 10). - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds (default: 60). ### Request Example ```typescript import { streamSpeechWithSubtitles } from "@bestcodes/edge-tts"; const { audio, subtitles } = await streamSpeechWithSubtitles({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", }); ``` ### Response #### Success Response - **audio** (Buffer) - The audio data buffer. - **subtitles** (string) - The generated subtitle content. ``` -------------------------------- ### Low-level API for Streaming Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use the Experimental_Raw.Communicate class for low-level control over speech streaming, processing audio data and word boundary metadata. ```typescript import { Experimental_Raw } from "@bestcodes/edge-tts"; const communicate = new Experimental_Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) } else if (chunk.type === "WordBoundary") { // Word boundary metadata } } ``` -------------------------------- ### Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=readme Provides a low-level API for direct communication with the TTS service, allowing streaming of audio and metadata. ```APIDOC ## Raw.Communicate ### Description Provides a low-level API for direct communication with the TTS service, allowing streaming of audio and metadata. ### Constructor `new Raw.Communicate(text: string, voice: string, options?: object)` ### Parameters #### Constructor Parameters - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Required - The voice to use. - **options** (object) - Optional - Additional options for communication (e.g., rate, volume, pitch, proxy, timeouts). ### Methods #### stream() - **Description**: Returns an async iterator that yields chunks of data (audio or metadata). - **Returns**: `AsyncIterableIterator` where each object has a `type` and `data` property. ### Request Example ```typescript import { Raw } from "@bestcodes/edge-tts"; const communicate = new Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) console.log("Received audio chunk"); } else if (chunk.type === "WordBoundary") { // Process word boundary metadata console.log("Received word boundary", chunk.data); } } ``` ### Response #### Success Response - **chunk.type** (string) - The type of data received (e.g., "audio", "WordBoundary"). - **chunk.data** (Buffer | object) - The actual data payload. For "audio", it's a Buffer. For metadata, it's an object. ``` -------------------------------- ### generateSpeechToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Generates speech from text and saves it directly to a specified file path. ```APIDOC ## generateSpeechToFile ### Description Generates speech from the provided text and saves the audio directly to a file at the specified output path. This is convenient for creating audio files without manual file handling. ### Method `generateSpeechToFile(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **outputPath** (string) - Required - The path where the audio file will be saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "Hello, world!", "outputPath": "./output.mp3" } ``` ### Response #### Success Response (200) This function returns a Promise that resolves when the file has been successfully written. No specific data is returned upon success. ``` -------------------------------- ### Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependencies Provides a low-level API for direct communication with the TTS service, allowing streaming of audio chunks and word boundary metadata. ```APIDOC ## Raw.Communicate ### Description Provides a low-level API for direct communication with the TTS service, allowing streaming of audio chunks and word boundary metadata. ### Method `new Raw.Communicate(text: string, voice: string)` ### Parameters #### Constructor Parameters - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Required - The voice to use for speech synthesis. ### Usage ```typescript import { Raw } from "@bestcodes/edge-tts"; const communicate = new Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) } else if (chunk.type === "WordBoundary") { // Word boundary metadata } } ``` ### Response #### Stream Chunks - **type** (string) - The type of the chunk, either "audio" or "WordBoundary". - **data** (Buffer or Object) - The data associated with the chunk. For "audio", it's the audio buffer. For "WordBoundary", it contains metadata. ``` -------------------------------- ### Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=code Provides a low-level API for direct communication with the Edge TTS service, allowing for granular control over streaming audio and metadata. ```APIDOC ## Raw.Communicate ### Description Provides a low-level API for direct communication with the Edge TTS service, allowing for granular control over streaming audio and metadata. ### Method `new Raw.Communicate(text: string, voice?: string)` ### Parameters #### Constructor Parameters - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". ### Usage This class provides a `stream()` method that returns an async iterator. ### Request Example ```javascript import { Raw } from "@bestcodes/edge-tts"; const communicate = new Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) } else if (chunk.type === "WordBoundary") { // Word boundary metadata } } ``` ### Response #### Success Response (from `stream()` iterator) - **chunk.type** (string) - The type of data received (e.g., "audio", "WordBoundary"). - **chunk.data** (Buffer | Object) - The data payload, which is a Buffer for audio or an object for metadata. ``` -------------------------------- ### Low-level Audio Streaming with Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Utilize the low-level Raw.Communicate API for granular control over audio streaming and word boundary events. ```typescript import { Raw } from "@bestcodes/edge-tts"; const communicate = new Raw.Communicate( "Hello!", "en-US-EmmaMultilingualNeural", ); for await (const chunk of communicate.stream()) { if (chunk.type === "audio") { // Process audio data (chunk.data is a Buffer) } else if (chunk.type === "WordBoundary") { // Word boundary metadata } } ``` -------------------------------- ### streamSpeechToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=readme Saves the audio output from text directly to a specified file path. ```APIDOC ## streamSpeechToFile ### Description Saves the audio output from text directly to a specified file path. ### Method `streamSpeechToFile` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **outputPath** (string) - Required - The file path where the audio will be saved. - **voice** (string) - Optional - The voice to use (default: "en-US-EmmaMultilingualNeural"). - **rate** (string) - Optional - The speech rate (e.g., "+10%" or "-20%"). Default: "+0%". - **volume** (string) - Optional - The speech volume (e.g., "+50%" or "-10%"). Default: "+0%". - **pitch** (string) - Optional - The speech pitch (e.g., "+10Hz" or "-5Hz"). Default: "+0Hz". - **boundary** (string) - Optional - The word or sentence boundary type ("WordBoundary" or "SentenceBoundary"). - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds (default: 10). - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds (default: 60). ### Request Example ```typescript import { streamSpeechToFile } from "@bestcodes/edge-tts"; await streamSpeechToFile({ text: "Hello, world!", outputPath: "./output.mp3", }); ``` ### Response This function does not return a value upon successful completion, but writes the audio to the specified `outputPath`. ``` -------------------------------- ### streamSpeechWithSubtitles Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=code Streams speech and generates SRT subtitles simultaneously. It returns both the audio data and the subtitle content. ```APIDOC ## streamSpeechWithSubtitles ### Description Streams speech and generates SRT subtitles simultaneously. It returns both the audio data and the subtitle content. ### Method `streamSpeechWithSubtitles` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **subtitlePath** (string) - Required - The path where the SRT subtitle file will be saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```javascript import { streamSpeechWithSubtitles } from "@bestcodes/edge-tts"; const { audio, subtitles } = await streamSpeechWithSubtitles({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", }); ``` ### Response #### Success Response - **audio** (Buffer) - The audio data buffer. - **subtitles** (string) - The generated SRT subtitle content. ``` -------------------------------- ### Stream Speech with Real-time Subtitles Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use streamSpeechWithSubtitlesToFile to stream audio and update subtitle files in real-time. Process both audio chunks and subtitle updates. ```typescript import { streamSpeechWithSubtitlesToFile } from "@bestcodes/edge-tts"; for await (const chunk of streamSpeechWithSubtitlesToFile({ text: "This text will have subtitles.", subtitlePath: "./subtitles.srt", })) { if (chunk.type === "audio" && chunk.data) { // Process audio chunk } else if (chunk.subtitles) { // Subtitles file updated in real-time console.log("Subtitles updated:", chunk.subtitles); } } ``` -------------------------------- ### Experimental_Raw.Communicate Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Provides low-level access to the Edge TTS communication stream for advanced use cases. ```APIDOC ## Experimental_Raw.Communicate ### Description This is a low-level API for direct communication with the Edge TTS service. It allows for granular control over the streaming process and access to raw audio and metadata chunks. ### Method `new Experimental_Raw.Communicate(text, voice, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Required - The voice to use for speech synthesis. - **options** (Object) - Optional - Additional options for communication, similar to other functions (e.g., `rate`, `volume`, `proxy`). ### Request Example ```json { "text": "Hello!", "voice": "en-US-EmmaMultilingualNeural" } ``` ### Response #### Success Response (200) The `communicate.stream()` method returns an async iterator yielding chunks. Each chunk can be: - `{ type: 'audio', data: Buffer }`: Contains raw audio data. - `{ type: 'WordBoundary', data: { start: number, end: number, text: string } }`: Word boundary metadata. ``` -------------------------------- ### Change Voice Rate, Pitch, and Volume Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/1.0.3 This snippet illustrates how to customize the speech output by adjusting the rate, pitch, and volume parameters. These options allow for fine-tuning the synthesized voice. ```javascript import { MsEdgeTTS, OUTPUT_FORMAT } from "msedge-tts"; (async () => { const tts = new MsEdgeTTS(); await tts.setMetadata( "en-US-AriaNeural", OUTPUT_FORMAT.WEBM_24KHZ_16BIT_MONO_OPUS ); const filePath = await tts.toFile( "./example_audio.webm", "Hi, how are you?", { rate: 0.5, pitch: "+200Hz" } ); })(); ``` -------------------------------- ### getVoices Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1?activeTab=code Retrieves a list of all available voices. ```APIDOC ## getVoices ### Description Retrieves a list of all available voices. ### Method `getVoices(): Promise>` ### Parameters None ### Request Example ```javascript import { getVoices } from "@bestcodes/edge-tts"; const allVoices = await getVoices(); ``` ### Response #### Success Response (200) - **allVoices** (Array) - A list of available voice objects. ``` -------------------------------- ### generateSpeech Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Generates speech from text and returns an audio buffer. This is a primary function for obtaining speech data directly. ```APIDOC ## generateSpeech ### Description Generates speech from the provided text and returns it as an audio buffer. This function is suitable for in-memory audio processing. ### Method `generateSpeech(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "Hello, world!", "voice": "en-US-EmmaMultilingualNeural" } ``` ### Response #### Success Response (200) - **audio** (Buffer) - The generated audio data. ``` -------------------------------- ### streamSpeech Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=readme Streams audio output from text. This function takes text and voice options and returns an audio buffer. ```APIDOC ## streamSpeech ### Description Streams audio output from text. This function takes text and voice options and returns an audio buffer. ### Method `streamSpeech` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use (default: "en-US-EmmaMultilingualNeural"). - **rate** (string) - Optional - The speech rate (e.g., "+10%" or "-20%"). Default: "+0%". - **volume** (string) - Optional - The speech volume (e.g., "+50%" or "-10%"). Default: "+0%". - **pitch** (string) - Optional - The speech pitch (e.g., "+10Hz" or "-5Hz"). Default: "+0Hz". - **boundary** (string) - Optional - The word or sentence boundary type ("WordBoundary" or "SentenceBoundary"). - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds (default: 10). - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds (default: 60). ### Request Example ```typescript import { streamSpeech } from "@bestcodes/edge-tts"; const audio = await streamSpeech({ text: "Hello, world!", voice: "en-US-EmmaMultilingualNeural", }); ``` ### Response #### Success Response - **audio** (Buffer) - The audio data buffer. ``` -------------------------------- ### streamSpeech Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/3.0.1 Streams audio chunks in real-time from the generated speech. Useful for immediate audio playback or processing. ```APIDOC ## streamSpeech ### Description Streams audio chunks in real-time as they are generated from the text. This allows for processing or playing audio without waiting for the entire speech to be synthesized. ### Method `streamSpeech(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A URL for a proxy server to use for the request. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```json { "text": "Hello, world!", "voice": "en-US-EmmaMultilingualNeural" } ``` ### Response #### Success Response (200) An async iterator yielding chunks. Each chunk can be: - `{ type: 'audio', data: Buffer }`: Contains audio data. - `{ type: 'WordBoundary', data: { start: number, end: number, text: string } }`: Word boundary metadata. ``` -------------------------------- ### streamSpeechToFile Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=code Streams speech and saves it directly to a specified file path. This is useful for generating audio files without manually handling the audio buffer. ```APIDOC ## streamSpeechToFile ### Description Streams speech and saves it directly to a specified file path. This is useful for generating audio files without manually handling the audio buffer. ### Method `streamSpeechToFile` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **outputPath** (string) - Required - The path where the audio file will be saved. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```javascript import { streamSpeechToFile } from "@bestcodes/edge-tts"; await streamSpeechToFile({ text: "Hello, world!", outputPath: "./output.mp3", }); ``` ### Response This function does not return a value upon successful completion, but saves the audio to the specified `outputPath`. ``` -------------------------------- ### Stream Audio Chunks Source: https://www.npmjs.com/package/@bestcodes/edge-tts Use streamSpeech to receive audio data in chunks for real-time processing. Specify the voice for generation. ```typescript import { streamSpeech } from "@bestcodes/edge-tts"; for await (const chunk of streamSpeech({ text: "Hello, world!", voice: "en-US-EmmaMultilingualNeural", })) { if (chunk.type === "audio" && chunk.data) { // Process audio chunk in real-time console.log(`Received ${chunk.data.length} bytes`); } } ``` -------------------------------- ### streamSpeech Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=code Streams speech audio as an audio buffer. This function takes text and voice options and returns a Promise that resolves with the audio data. ```APIDOC ## streamSpeech ### Description Streams speech audio as an audio buffer. This function takes text and voice options and returns a Promise that resolves with the audio data. ### Method `streamSpeech` ### Parameters #### Options Object - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use for speech synthesis. Defaults to "en-US-EmmaMultilingualNeural". - **rate** (string) - Optional - The speech rate, e.g., "+10%" or "-20%". Defaults to "+0%". - **volume** (string) - Optional - The speech volume, e.g., "+50%" or "-10%". Defaults to "+0%". - **pitch** (string) - Optional - The speech pitch, e.g., "+10Hz" or "-5Hz". Defaults to "+0Hz". - **boundary** (string) - Optional - The boundary type for speech, either "WordBoundary" or "SentenceBoundary". - **proxy** (string) - Optional - A proxy URL to use for the connection. - **connectTimeoutSeconds** (number) - Optional - The connection timeout in seconds. Defaults to 10. - **receiveTimeoutSeconds** (number) - Optional - The receive timeout in seconds. Defaults to 60. ### Request Example ```javascript import { streamSpeech } from "@bestcodes/edge-tts"; const audio = await streamSpeech({ text: "Hello, world!", voice: "en-US-EmmaMultilingualNeural", }); ``` ### Response #### Success Response - **audio** (Buffer) - The audio data buffer. ``` -------------------------------- ### List All Voices with getVoices Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Retrieve a list of all available TTS voices using the getVoices function. ```typescript import { getVoices, findVoices } from "@bestcodes/edge-tts"; // Get all voices const allVoices = await getVoices(); ``` -------------------------------- ### Default SSML Object Structure Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/1.0.3 This is the default SSML object structure used by the library for text-to-speech synthesis. ```xml ${input} ``` -------------------------------- ### getVoices Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=code Retrieves a list of all available voices supported by the Edge TTS service. ```APIDOC ## getVoices ### Description Retrieves a list of all available voices supported by the Edge TTS service. ### Method `getVoices` ### Parameters This method does not accept any parameters. ### Request Example ```javascript import { getVoices } from "@bestcodes/edge-tts"; const allVoices = await getVoices(); ``` ### Response #### Success Response - **voices** (Array) - An array of voice objects, each containing details about an available voice. ``` -------------------------------- ### getVoices Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=readme Retrieves a list of all available voices supported by the Edge TTS service. ```APIDOC ## getVoices ### Description Retrieves a list of all available voices supported by the Edge TTS service. ### Method `getVoices` ### Parameters This function does not accept any parameters. ### Request Example ```typescript import { getVoices } from "@bestcodes/edge-tts"; const allVoices = await getVoices(); ``` ### Response #### Success Response - **allVoices** (Array) - An array of voice objects, each containing details about an available voice. ``` -------------------------------- ### Find Specific Voices with findVoices Source: https://www.npmjs.com/package/%40bestcodes/edge-tts/v/2.0.0?activeTab=dependents Filter and find specific voices based on criteria like Gender or Locale using the findVoices function. ```typescript import { getVoices, findVoices } from "@bestcodes/edge-tts"; // Find specific voices const femaleVoices = await findVoices({ Gender: "Female" }); const englishVoices = await findVoices({ Locale: "en-US" }); ```