Service that fetches available voices and converts text to speech using EdgeTTS, returning base64 audio.
// Source: https://github.com/Lucassssss/eechat | License: Apache-2.0 | Copyright 2024 9tharts <lucas@9tharts.com>
// Provided via justclaw.it.com; keep this notice with the code.
const { Service } = require('egg')
const { EdgeTTS, VoiceList } = require('node-edge-tts')
const fs = require('fs')
const path = require('path')
const paths = require('../../config/paths')
module.exports = class TtsService extends Service {
constructor(ctx) {
super(ctx)
this.tempDir = path.join(paths.tmpPath, 'tts')
// 确保临时目录存在
if (!fs.existsSync(this.tempDir)) {
fs.mkdirSync(this.tempDir, { recursive: true })
}
}
/**
* 获取可用的语音列表
* @returns {Promise<Array>} 语音列表
*/
async getVoices() {
try {
// 从 Bing API 获取语音列表
const response = await this.ctx.curl(
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key