diff --git a/src/utils/decodeYrc.js b/src/utils/decodeYrc.js index 50d775c..fee53bc 100644 --- a/src/utils/decodeYrc.js +++ b/src/utils/decodeYrc.js @@ -1,5 +1,6 @@ /** * Decode yrc text + * Made by Pizero * @param {string} i - yrc input * @returns {[number,number,[[number,number],string,number,number][]]} */ diff --git a/src/utils/speech.js b/src/utils/speech.js index ea4e79d..12457bd 100644 --- a/src/utils/speech.js +++ b/src/utils/speech.js @@ -3,8 +3,22 @@ let audioQueue = []; let isPlaying = false; let controller = null; // 用于取消请求 +/** + * Speech + * Made by NanoRocky + * 使用指定参数生成语音并播放音频。 + * 该功能原为 Azure 设计,理应兼容大部分使用 post 传参的 api 。请自行根据要求修改!如果也使用 Azure ,您可直接使用 https://github.com/NanoRocky/AzureSpeechAPI-by-PHP 完成 API 部署 + * https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/speech-synthesis-markup-voice + * + * @param {string} text - 朗读的文本 + * @param {string} [voice="zh-CN-YunxiaNeural"] - 音色(默认为“zh-CN-YunxiaNeural”) + * @param {string} [style="cheerful"] - 声音特定的讲话风格(默认为“cheerful”) + * @param {string} [role="Boy"] - 讲话角色扮演(默认为“Boy”) + * @param {string} [rate="1"] - 语速(默认为“1”) + * @param {string} [volume="100"] - 音量(默认为“100”) + * @returns {Promise} - 一个 Promise,在语音播放完成时解析或出现错误时拒绝 + */ export function Speech( - // 该功能原为 Azure 设计,理应兼容大部分使用 post 传参的 api 。请自行根据要求修改! text, voice = "zh-CN-YunxiaNeural", style = "cheerful", @@ -95,7 +109,9 @@ export function Speech( }); } -// 添加停止播放的函数 +/** + * 停止当前播放的语音,并清空播放队列。 + */ export function stopSpeech() { if (currentAudio) { currentAudio.pause(); @@ -109,8 +125,16 @@ export function stopSpeech() { } } +/** + * SpeechLocal + * Made by NanoRocky + * 播放本地预生成的语音音频。 + * 考虑到生成延迟,所以加了这个,仅必要模块调用 api 实时生成,其它模块使用预先生成好的音频。记得根据需求更换自己的音频文件哇! + * + * @param {string} fileName - 音频文件名 + 文件拓展名(请将文件放在指定路径) + * @returns {Promise} - 一个 Promise,在语音播放完成时解析或出现错误时拒绝 + */ export function SpeechLocal(fileName) { - // 考虑到生成延迟,所以加了这个,仅必要模块调用 api 实时生成,其它模块使用预先生成好的音频。记得根据需求更换自己的音频文件哇! return new Promise((resolve, reject) => { if (!fileName) { reject(new Error("No file name provided"));