十一实验室 NodeJS 包用于将文本转换为语音!
报告错误·请求功能
在 GitHub 上给我们留言,以帮助项目改进!
这是一个开源 Eleven Labs NodeJS 包,用于使用 Eleven Labs API 将文本转换为语音。
功能 | 参数 | 端点 |
---|---|---|
textToSpeech | ({voiceId、文件名、textInput、稳定性、similarBoost、modelId、风格、speakerBoost}) | /v1/text-to-speech/{voice_id} |
textToSpeechStream | ({voiceId、textInput、稳定性、similarBoost、modelId、responseType、风格、speakerBoost}) | /v1/text-to-speech/{voice_id}/stream |
editVoiceSettings | ({voiceId,稳定性,相似度Boost}) | /v1/voices/{voice_id}/settings/edit |
getVoiceSettings | ({语音ID}) | /v1/voices/{voice_id}/settings |
deleteVoice | ({语音ID}) | /v1/voices/{voice_id} |
getVoice | ({语音ID}) | /v1/voices/{voice_id} |
getVoices | 不适用 | /v1/voices |
getModels | 不适用 | /v1/models |
getUserInfo | 不适用 | /v1/user |
getUserSubscription | 不适用 | /v1/user/subscription |
getDefaultVoiceSettings | 不适用 | /v1/voices/settings/default |
多变的 | 描述 | 类型 |
---|---|---|
fileName | 音频文件的名称和文件路径,例如 ( ./gen/hello ) | String |
textInput | 要转换为音频的文本例如( Hello ) | String |
stability | 文本转语音的稳定性默认值 ( 0 ) | Float |
similarityBoost | 文本转语音的相似度提升默认值 ( 0 ) | Float |
voiceId | ElevenLabs 语音 ID 例如 ( pNInz6obpgDQGcFmaJgB ) | String |
modelId | ElevenLabs 模型 ID 例如 ( eleven_multilingual_v2 ) | String |
responseType | 流响应类型例如( stream ) | String |
speakerBoost | 文本到语音的扬声器增强例如( true ) | Boolean |
style | 文本转语音的样式夸张 (0-100) 默认值 ( 0 ) | Integer |
要安装 Elevenlabs 软件包,请运行以下命令:
npm install elevenlabs-node
为您的项目设置 ElevenLabs 配置。
多变的 | 描述 | 默认 |
---|---|---|
apiKey | ( Required )您来自 Elevenlabs 的 API 密钥 | 不适用 |
voiceId | ( Optional )Elevenlabs 的语音 ID | 亚当 ( pNInz6obpgDQGcFmaJgB ) |
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
voiceId : "pNInz6obpgDQGcFmaJgB" , // A Voice ID from Elevenlabs
}
) ;
从文本生成音频文件。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
voiceId : "pNInz6obpgDQGcFmaJgB" , // A Voice ID from Elevenlabs
}
) ;
voice . textToSpeech ( {
// Required Parameters
fileName : "audio.mp3" , // The name of your audio file
textInput : "mozzy is cool" , // The text you wish to convert to speech
// Optional Parameters
voiceId : "21m00Tcm4TlvDq8ikWAM" , // A different Voice ID from the default
stability : 0.5 , // The stability for the converted speech
similarityBoost : 0.5 , // The similarity boost for the converted speech
modelId : "eleven_multilingual_v2" , // The ElevenLabs Model ID
style : 1 , // The style exaggeration for the converted speech
speakerBoost : true // The speaker boost for the converted speech
} ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
从文本生成音频流。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const fs = require ( "fs-extra" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
voiceId : "pNInz6obpgDQGcFmaJgB" , // A Voice ID from Elevenlabs
}
) ;
const voiceResponse = voice . textToSpeechStream ( {
// Required Parameters
textInput : "mozzy is cool" , // The text you wish to convert to speech
// Optional Parameters
voiceId : "21m00Tcm4TlvDq8ikWAM" , // A different Voice ID from the default
stability : 0.5 , // The stability for the converted speech
similarityBoost : 0.5 , // The similarity boost for the converted speech
modelId : "eleven_multilingual_v2" , // The ElevenLabs Model ID
style : 1 , // The style exaggeration for the converted speech
responseType : "stream" , // The streaming type (arraybuffer, stream, json)
speakerBoost : true // The speaker boost for the converted speech
} ) . then ( ( res ) => {
res . pipe ( fs . createWriteStream ( fileName ) ) ;
} ) ;
编辑语音设置。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . editVoiceSettings ( {
// Required Parameters
voiceId : "pNInz6obpgDQGcFmaJgB" , // The ID of the voice you want to edit
stabilityBoost : 0.5 , // The Stability Boost for the voice
similarityBoost : 0.5 , // The Similarity Boost for the voice
} ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取语音设置。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getVoiceSettings ( {
// Required Parameters
voiceId : "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get
} ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
删除语音。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . deleteVoice ( {
// Required Parameters
voiceId : "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to delete
} ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取语音详细信息。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getVoice ( {
// Required Parameters
voiceId : "pNInz6obpgDQGcFmaJgB" // The ID of the voice you want to get
} ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取所有语音详细信息。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getVoices ( ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取所有模型详细信息。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getModels ( ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取与 API 密钥关联的用户信息。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getUserInfo ( ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取与 API 密钥关联的用户订阅信息。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getUserSubscription ( ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
获取默认语音设置。
const ElevenLabs = require ( "elevenlabs-node" ) ;
const voice = new ElevenLabs (
{
apiKey : "0e2c037kl8561005671b1de345s8765c" , // Your API key from Elevenlabs
}
) ;
const voiceResponse = voice . getDefaultVoiceSettings ( ) . then ( ( res ) => {
console . log ( res ) ;
} ) ;
欢迎贡献:)
请阅读我们的 CONTRIBUTING.md 以了解更多信息。