### Install text2wav.node.js
Source: https://github.com/abbr/text2wav.node.js/blob/master/README.md
Instructions for installing the text2wav.node.js module for use as an API or a command-line interface (CLI) tool. It can be installed locally for project use or globally for system-wide access.
```bash
npm i -S text2wav
```
```bash
npm i -g text2wav
```
--------------------------------
### Node.js: Complete Options Example for text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates comprehensive usage of text2wav in Node.js by combining multiple options for voice, speed, pitch, amplitude, word gap, capital sounds, SSML parsing, and encoding. It generates WAV audio data and saves it to a file.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function completeExample() {
const options = {
voice: 'en-US+f2', // American English, female variant
speed: 150, // Slightly slower than default
pitch: 60, // Slightly higher pitch
amplitude: 120, // Slightly louder
wordGap: 2, // Small pause between words
capital: 1, // Sound for capitals
hasTags: true, // Enable SSML parsing
noFinalPause: false, // Keep final pause
encoding: 1 // UTF-8
}
const text = '
Welcome
This is a TEST message from the USA.'
const wavData = await text2wav(text, options)
fs.writeFileSync('complete_example.wav', Buffer.from(wavData))
console.log(`Generated ${wavData.length} bytes of audio data`)
}
completeExample()
```
--------------------------------
### CLI: Basic and Advanced text2wav Command-Line Usage
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Provides examples of using the text2wav module as a command-line tool. It covers basic text-to-WAV conversion, specifying languages, voice variants, adjusting speech parameters like speed, pitch, amplitude, word gaps, and handling SSML tags.
```bash
# Install globally
npm install -g text2wav
# Basic usage - output to file
text2wav "Hello, world!" > hello.wav
# Specify voice/language
text2wav "你好世界" -v zh > chinese.wav
text2wav "Bonjour le monde" -v fr > french.wav
# Use voice variant (whisper)
text2wav "This is a secret" -v en+whisper > whisper.wav
# Adjust speed (words per minute)
text2wav "Speaking slowly" -s 100 > slow.wav
text2wav "Speaking quickly" -s 250 > fast.wav
# Adjust pitch (0-99)
text2wav "High pitched voice" -p 80 > high.wav
text2wav "Low pitched voice" -p 20 > low.wav
# Adjust amplitude/volume (0-200)
text2wav "Quiet voice" -a 50 > quiet.wav
text2wav "Loud voice" -a 150 > loud.wav
# Add word gaps (units of 10ms)
text2wav "Spaced out words" -g 10 > spaced.wav
# Indicate capitals
text2wav "NASA and FBI agents" -k 2 > capitals.wav
# Enable SSML/HTML tags
text2wav "Title
Content here
" -m > tagged.wav
# Speak specific punctuation
text2wav '"Hello," she said.' --punct='"' > quotes.wav
# Combine multiple options
text2wav "Complete example" -v en-US -s 150 -p 55 -a 110 > combined.wav
# Pipe to audio player (if available)
text2wav "Playing directly" | aplay
```
--------------------------------
### Adjusting Speech Speed and Pitch with text2wav Options
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates how to control the speech rate (words per minute) and pitch of the synthesized voice using the 'speed' and 'pitch' options in the text2wav function. Examples include slow, fast, high pitch, low pitch, and combined settings.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function speedAndPitchDemo() {
const text = 'The quick brown fox jumps over the lazy dog.'
// Slow speech (100 wpm)
const slow = await text2wav(text, { speed: 100 })
fs.writeFileSync('slow.wav', Buffer.from(slow))
// Fast speech (250 wpm)
const fast = await text2wav(text, { speed: 250 })
fs.writeFileSync('fast.wav', Buffer.from(fast))
// High pitch (80)
const highPitch = await text2wav(text, { pitch: 80 })
fs.writeFileSync('high_pitch.wav', Buffer.from(highPitch))
// Low pitch (20)
const lowPitch = await text2wav(text, { pitch: 20 })
fs.writeFileSync('low_pitch.wav', Buffer.from(lowPitch))
// Combined: slow with high pitch
const combined = await text2wav(text, { speed: 120, pitch: 70 })
fs.writeFileSync('slow_high.wav', Buffer.from(combined))
}
speedAndPitchDemo()
```
--------------------------------
### Use text2wav.node.js CLI
Source: https://github.com/abbr/text2wav.node.js/blob/master/README.md
Shows how to utilize the text2wav.node.js command-line interface (CLI) to convert text to WAV audio. The output is directed to standard output, allowing it to be easily piped to files or other processes.
```bash
text2wav []
```
```bash
text2wav test > test.wav
```
```bash
text2wav '测试' -v zh > test.wav
```
```bash
text2wav test -v en+whisper > test.wav
```
```bash
text2wav '"test", I say.' --punct='"' > test.wav
```
--------------------------------
### Use text2wav.node.js API
Source: https://github.com/abbr/text2wav.node.js/blob/master/README.md
Demonstrates how to use the text2wav.node.js module within JavaScript and TypeScript projects. The API takes text and optional configuration objects as input and returns the WAV audio content as a Uint8Array.
```javascript
const text2wav = require('text2wav')
let out = await text2wav([,])
```
```typescript
import text2wav = require('text2wav')
let out = await text2wav([,])
```
```javascript
(async () => {
const text2wav = require('text2wav')
let out = await text2wav('test')
const assert = require('assert')
assert.equal(out[0], 82)
assert.equal(out[1], 73)
assert.equal(out[2], 70)
assert.equal(out[3], 70)
})()
```
```javascript
let out = await text2wav('测试', {voice: 'zh'})
```
```javascript
let out = await text2wav('test', {voice: 'en+whisper'})
```
```javascript
let out = await text2wav('"test", I say.', {punct: '"'})
```
--------------------------------
### Compile espeak-ng to WebAssembly
Source: https://github.com/abbr/text2wav.node.js/blob/master/README.md
A series of shell commands to clone the espeak-ng repository, configure the build environment with Emscripten, and compile the source into JavaScript and WebAssembly modules.
```bash
git clone https://github.com/espeak-ng/espeak-ng.git
cd espeak-ng
./autogen.sh
./configure --without-async --with-extdict-zh --with-extdict-zhy --with-extdict-ru
make
cd src/ucd-tools/
./autogen.sh
make clean
emconfigure ./configure
emmake make
cd ../..
emconfigure ./configure --without-async --without-mbrola --without-sonic --enable-shared=false
emmake make src/espeak-ng
mv src/espeak-ng src/espeak-ng.bc
emcc -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s MODULARIZE=1 -s 'EXPORT_NAME="EspeakNg"' -o espeak-ng.js src/espeak-ng.bc
echo // espeak-ng git hash `git rev-parse HEAD` >> espeak-ng.js
```
--------------------------------
### Basic Text to WAV Conversion in Node.js
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates the basic usage of the text2wav function to convert a simple text string into WAV audio data and save it to a file. It includes verification of the WAV header.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
// Basic usage - convert text to WAV
async function basicSpeech() {
const wavData = await text2wav('Hello, world!')
// Verify WAV header (RIFF format)
console.log(String.fromCharCode(wavData[0], wavData[1], wavData[2], wavData[3])) // "RIFF"
// Save to file
fs.writeFileSync('output.wav', Buffer.from(wavData))
}
basicSpeech()
```
--------------------------------
### Node.js: Error Handling with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates robust error handling for the text2wav Node.js function. It shows how to use try-catch blocks to gracefully manage potential errors arising from invalid options during speech synthesis.
```javascript
const text2wav = require('text2wav')
async function errorHandlingDemo() {
try {
// Invalid option will throw
await text2wav('test', { invalidOption: true })
} catch (error) {
console.error('Error:', error.message) // "invalid option invalidOption"
}
try {
// Valid usage
const wav = await text2wav('Hello', { voice: 'en', speed: 175 })
console.log('Success! Generated', wav.length, 'bytes')
} catch (error) {
console.error('Synthesis failed:', error.message)
}
}
errorHandlingDemo()
```
--------------------------------
### TypeScript: Usage with Type Definitions for text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Illustrates how to use the text2wav library in TypeScript, leveraging its provided type definitions for improved code safety and IDE support. It defines a `SpeechConfig` interface and demonstrates synthesizing speech with specific configurations.
```typescript
import text2wav = require('text2wav')
import * as fs from 'fs'
interface SpeechConfig {
voice?: string
amplitude?: number
wordGap?: number
capital?: number
lineLength?: number
pitch?: number
speed?: number
encoding?: number
hasTags?: boolean
noFinalPause?: boolean
punct?: string
}
async function typescriptExample(): Promise {
const config: SpeechConfig = {
voice: 'en',
speed: 175,
pitch: 50
}
const wavData: Uint8Array = await text2wav('Hello from TypeScript!', config)
fs.writeFileSync('typescript_output.wav', Buffer.from(wavData))
}
typescriptExample()
```
--------------------------------
### SSML Tags Support Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Enable interpretation of SSML and basic HTML tags for speech control.
```APIDOC
## SSML Tags Support Option
### Description
Enables the interpretation of SSML (Speech Synthesis Markup Language) and basic HTML tags for speech control.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text containing SSML or HTML tags.
- **hasTags** (boolean) - Optional - Set to `true` to enable tag interpretation (default: false).
### Request Example
```json
{
"text": "Important Announcement
Please listen carefully.
",
"hasTags": true
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Multilingual Text to WAV Synthesis with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Shows how to use the 'voice' option in text2wav to synthesize speech in various languages including English, Chinese, Spanish, French, and specific regional variants like American and Scottish English.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function multilingualSpeech() {
// English (default)
const english = await text2wav('Hello, how are you?', { voice: 'en' })
fs.writeFileSync('english.wav', Buffer.from(english))
// Chinese
const chinese = await text2wav('你好,世界', { voice: 'zh' })
fs.writeFileSync('chinese.wav', Buffer.from(chinese))
// Spanish
const spanish = await text2wav('Hola, ¿cómo estás?', { voice: 'es' })
fs.writeFileSync('spanish.wav', Buffer.from(spanish))
// French
const french = await text2wav('Bonjour, comment allez-vous?', { voice: 'fr' })
fs.writeFileSync('french.wav', Buffer.from(french))
// American English
const american = await text2wav('Hello from America!', { voice: 'en-US' })
fs.writeFileSync('american.wav', Buffer.from(american))
// British English with Scottish accent
const scottish = await text2wav('Hello from Scotland!', { voice: 'en-GB-scotland' })
fs.writeFileSync('scottish.wav', Buffer.from(scottish))
}
multilingualSpeech()
```
--------------------------------
### Amplitude and Word Gap Options
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Control audio volume and add pauses between words.
```APIDOC
## Amplitude and Word Gap Options
### Description
Controls audio volume and adds pauses between words.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **amplitude** (number) - Optional - Controls volume from 0 to 200 (default: 100).
- **wordGap** (number) - Optional - Adds pauses between words in units of 10ms at default speed.
### Request Example
```json
{
"text": "One two three four five",
"amplitude": 50,
"wordGap": 5
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Indicate Capital Letters in Speech with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Shows how to use the 'capital' option to indicate capital letters. Options include a sound effect (1), saying the word 'capitals' (2), or increasing the pitch (values > 2).
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function capitalIndicationDemo() {
const text = 'The NASA and FBI agents met at the USA embassy.'
// Sound indication for capitals
const soundCaps = await text2wav(text, { capital: 1 })
fs.writeFileSync('caps_sound.wav', Buffer.from(soundCaps))
// Say "capitals" for capital letters
const sayCaps = await text2wav(text, { capital: 2 })
fs.writeFileSync('caps_word.wav', Buffer.from(sayCaps))
// Pitch increase for capitals (value of 20)
const pitchCaps = await text2wav(text, { capital: 20 })
fs.writeFileSync('caps_pitch.wav', Buffer.from(pitchCaps))
}
capitalIndicationDemo()
```
--------------------------------
### Utilize SSML and HTML Tags for Speech Control with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates the 'hasTags' option, which enables the interpretation of basic SSML and HTML tags within the input text for controlling speech elements like emphasis and pauses.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function ssmlDemo() {
// Using HTML-like tags for emphasis
const htmlText = 'Important Announcement
Please listen carefully.
Thank you.'
const htmlSpeech = await text2wav(htmlText, { hasTags: true })
fs.writeFileSync('html_tags.wav', Buffer.from(htmlSpeech))
// Using list items for pauses
const listText = 'First itemSecond itemThird item'
const listSpeech = await text2wav(listText, { hasTags: true })
fs.writeFileSync('list_tags.wav', Buffer.from(listSpeech))
}
ssmlDemo()
```
--------------------------------
### Control Speech Volume and Word Pauses with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates how to adjust speech volume using the 'amplitude' option (0-200) and control pauses between words with 'wordGap' (in 10ms units). Higher 'wordGap' values with slower 'speed' can simulate dictation.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function amplitudeAndGapDemo() {
const text = 'One two three four five'
// Quiet speech (50% volume)
const quiet = await text2wav(text, { amplitude: 50 })
fs.writeFileSync('quiet.wav', Buffer.from(quiet))
// Loud speech (150% volume)
const loud = await text2wav(text, { amplitude: 150 })
fs.writeFileSync('loud.wav', Buffer.from(loud))
// Add 50ms gap between words
const spaced = await text2wav(text, { wordGap: 5 })
fs.writeFileSync('spaced.wav', Buffer.from(spaced))
// Very slow reading with large gaps
const dictation = await text2wav(text, { wordGap: 20, speed: 100 })
fs.writeFileSync('dictation.wav', Buffer.from(dictation))
}
amplitudeAndGapDemo()
```
--------------------------------
### POST /text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Synthesizes text into audio data using the provided configuration options.
```APIDOC
## POST /text2wav
### Description
Converts input text into a WAV audio buffer based on the provided speech synthesis configuration.
### Method
POST
### Endpoint
text2wav(text, options)
### Parameters
#### Request Body
- **text** (string) - Required - The text content to be synthesized.
- **options** (object) - Optional - Configuration object for speech synthesis:
- **voice** (string) - Optional - Voice identifier (e.g., 'en-US+f2').
- **speed** (number) - Optional - Words per minute (default: 175).
- **pitch** (number) - Optional - Pitch level (0-99).
- **amplitude** (number) - Optional - Volume level (0-200).
- **wordGap** (number) - Optional - Pause between words.
- **hasTags** (boolean) - Optional - Enable SSML/HTML tag parsing.
- **encoding** (number) - Optional - Character encoding (e.g., 1 for UTF-8).
### Request Example
{
"text": "Hello World",
"options": {
"voice": "en",
"speed": 150,
"pitch": 50
}
}
### Response
#### Success Response (200)
- **wavData** (Uint8Array) - The generated audio data in WAV format.
#### Response Example
{ "wavData": [82, 73, 70, 70, ...] }
```
--------------------------------
### Text Encoding Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Specify the input text encoding.
```APIDOC
## Text Encoding Option
### Description
Specifies the input text encoding.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **encoding** (number) - Optional - Specifies input text encoding: 1=UTF-8 (default), 2=8-bit, 4=16-bit.
### Request Example
```json
{
"text": "Héllo Wörld",
"encoding": 1
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Specify Input Text Encoding with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Explains the 'encoding' option for setting the input text encoding. Supported values are 1 for UTF-8 (default), 2 for 8-bit, and 4 for 16-bit encoding, ensuring correct character interpretation.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function encodingDemo() {
// UTF-8 encoding (default)
const utf8 = await text2wav('Héllo Wörld', { encoding: 1 })
fs.writeFileSync('utf8.wav', Buffer.from(utf8))
}
encodingDemo()
```
--------------------------------
### Punctuation Speaking Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Configure which punctuation characters are spoken.
```APIDOC
## Punctuation Speaking Option
### Description
Configures the speaking of punctuation characters.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **punct** (string | boolean) - Optional - Set to `true` to speak all punctuation, or provide a string of specific punctuation characters to speak (e.g., `"` or `$.`).
### Request Example
```json
{
"text": "\"Hello,\" she said. \"How are you?\"",
"punct": "\""
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Customizing Voices with Variants in text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Illustrates the use of voice variants with the 'voice' option in text2wav to apply effects like whisper or croak, and to select different male or female voice types. It also shows combining variants with different languages.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function voiceVariants() {
// Whisper effect
const whisper = await text2wav('This is a secret message', { voice: 'en+whisper' })
fs.writeFileSync('whisper.wav', Buffer.from(whisper))
// Male voice variant (m3)
const male = await text2wav('Hello, I am a male voice', { voice: 'en+m3' })
fs.writeFileSync('male.wav', Buffer.from(male))
// Female voice variant (f2)
const female = await text2wav('Hello, I am a female voice', { voice: 'en+f2' })
fs.writeFileSync('female.wav', Buffer.from(female))
// Croak effect
const croak = await text2wav('I have a frog in my throat', { voice: 'en+croak' })
fs.writeFileSync('croak.wav', Buffer.from(croak))
// Afrikaans with male variant
const afMale = await text2wav('Hallo wêreld', { voice: 'af+m3' })
fs.writeFileSync('afrikaans_male.wav', Buffer.from(afMale))
}
voiceVariants()
```
--------------------------------
### Capital Letters Indication Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Configure how capital letters are handled during speech synthesis.
```APIDOC
## Capital Letters Indication Option
### Description
Indicates how capital letters should be treated during speech synthesis.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **capital** (number) - Optional - Controls capital letter indication: 1=sound, 2=say "capitals", higher values increase pitch (default: 0).
### Request Example
```json
{
"text": "The NASA and FBI agents met at the USA embassy.",
"capital": 2
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Manage Pauses with Line Length in text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Introduces the 'lineLength' option, which treats lines shorter than the specified length as the end of a clause, inserting appropriate pauses. This is useful for poetic or structured text.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function lineLengthDemo() {
const poem = `Roses are red
Violets are blue
Sugar is sweet
And so are you`
// Treat each short line as a clause
const poetic = await text2wav(poem, { lineLength: 20 })
fs.writeFileSync('poem.wav', Buffer.from(poetic))
}
lineLengthDemo()
```
--------------------------------
### Line Length Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Treat lines shorter than a specified length as end-of-clause.
```APIDOC
## Line Length Option
### Description
Treats lines shorter than the specified length as end-of-clause, adding appropriate pauses.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **lineLength** (number) - Optional - The maximum length of a line to be treated as an end-of-clause.
### Request Example
```json
{
"text": "Roses are red\nViolets are blue",
"lineLength": 20
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Control Punctuation Speaking with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Explains the 'punct' option for controlling which punctuation characters are spoken. It can be set to true to speak all punctuation or a string specifying particular characters to include.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function punctuationDemo() {
const text = '"Hello," she said. "How are you?"'
// Speak only double quotes
const quotesOnly = await text2wav(text, { punct: '"' })
fs.writeFileSync('quotes.wav', Buffer.from(quotesOnly))
// Speak specific punctuation
const custom = await text2wav('Price: $99.99 (50% off!)', { punct: '$%' })
fs.writeFileSync('custom_punct.wav', Buffer.from(custom))
}
punctuationDemo()
```
--------------------------------
### No Final Pause Option
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Remove the default sentence pause at the end of the text.
```APIDOC
## No Final Pause Option
### Description
Removes the default sentence pause at the end of the text, useful for concatenating audio segments.
### Method
POST
### Endpoint
/text2wav
### Parameters
#### Request Body
- **text** (string) - Required - The text to convert to speech.
- **noFinalPause** (boolean) - Optional - Set to `true` to remove the final pause (default: false).
### Request Example
```json
{
"text": "First part.",
"noFinalPause": true
}
```
### Response
#### Success Response (200)
- **audio_data** (Buffer) - The generated WAV audio data.
#### Response Example
(Binary audio data)
```
--------------------------------
### Disable Final Pause for Concatenation with text2wav
Source: https://context7.com/abbr/text2wav.node.js/llms.txt
Demonstrates the 'noFinalPause' option, which removes the default pause at the end of synthesized speech. This is beneficial when concatenating multiple audio segments to ensure seamless transitions.
```javascript
const text2wav = require('text2wav')
const fs = require('fs')
async function noFinalPauseDemo() {
// With final pause (default)
const withPause = await text2wav('First part.', { noFinalPause: false })
// Without final pause - for seamless concatenation
const noPause = await text2wav('First part.', { noFinalPause: true })
fs.writeFileSync('with_pause.wav', Buffer.from(withPause))
fs.writeFileSync('no_pause.wav', Buffer.from(noPause))
}
noFinalPauseDemo()
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.