@lobehub/ui 1.108.2 → 1.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/useTTS/data/azureVoiceListFull.json +2156 -0
- package/es/useTTS/data/azureVoiceListLite.json +358 -0
- package/es/useTTS/hooks/useAzureSpeech.d.ts +11 -0
- package/es/useTTS/hooks/useAzureSpeech.js +39 -0
- package/es/useTTS/hooks/useMicrosoftSpeech.d.ts +9 -0
- package/es/useTTS/hooks/useMicrosoftSpeech.js +39 -0
- package/es/useTTS/hooks/useSpeechRecognition.d.ts +6 -0
- package/es/useTTS/hooks/useSpeechRecognition.js +53 -0
- package/es/useTTS/hooks/useSpeechSynthes.d.ts +8 -0
- package/es/useTTS/hooks/useSpeechSynthes.js +38 -0
- package/es/useTTS/index.d.ts +5 -0
- package/es/useTTS/index.js +5 -0
- package/es/useTTS/services/postAzureSpeech.d.ts +7 -0
- package/es/useTTS/services/postAzureSpeech.js +45 -0
- package/es/useTTS/services/postMicrosoftSpeech.d.ts +2 -0
- package/es/useTTS/services/postMicrosoftSpeech.js +64 -0
- package/es/useTTS/utils/genSSML.d.ts +9 -0
- package/es/useTTS/utils/genSSML.js +15 -0
- package/es/useTTS/utils/getVoiceList.d.ts +11 -0
- package/es/useTTS/utils/getVoiceList.js +35 -0
- package/package.json +5 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { genSSML } from "../utils/genSSML";
|
|
5
|
+
export var postMicrosoftSpeech = /*#__PURE__*/function () {
|
|
6
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, options) {
|
|
7
|
+
var data, DEFAULT_HEADERS, response;
|
|
8
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
9
|
+
while (1) switch (_context.prev = _context.next) {
|
|
10
|
+
case 0:
|
|
11
|
+
data = JSON.stringify({
|
|
12
|
+
offsetInPlainText: 0,
|
|
13
|
+
properties: {
|
|
14
|
+
SpeakTriggerSource: 'AccTuningPagePlayButton'
|
|
15
|
+
},
|
|
16
|
+
ssml: genSSML(text, options),
|
|
17
|
+
ttsAudioFormat: 'audio-24khz-160kbitrate-mono-mp3'
|
|
18
|
+
});
|
|
19
|
+
DEFAULT_HEADERS = {
|
|
20
|
+
'accept': '*/*',
|
|
21
|
+
'accept-language': 'zh-CN,zh;q=0.9',
|
|
22
|
+
'authority': 'southeastasia.api.speech.microsoft.com',
|
|
23
|
+
'content-type': 'application/json',
|
|
24
|
+
'customvoiceconnectionid': uuidv4(),
|
|
25
|
+
'origin': 'https://speech.microsoft.com',
|
|
26
|
+
'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
|
27
|
+
'sec-ch-ua-mobile': '?0',
|
|
28
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
29
|
+
'sec-fetch-dest': 'empty',
|
|
30
|
+
'sec-fetch-mode': 'no-cors',
|
|
31
|
+
'sec-fetch-site': 'same-site',
|
|
32
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
|
|
33
|
+
};
|
|
34
|
+
_context.prev = 2;
|
|
35
|
+
_context.next = 5;
|
|
36
|
+
return fetch('https://southeastasia.api.speech.microsoft.com/accfreetrial/texttospeech/acc/v3.0-beta1/vcg/speak', {
|
|
37
|
+
body: data,
|
|
38
|
+
headers: DEFAULT_HEADERS,
|
|
39
|
+
method: 'POST',
|
|
40
|
+
mode: 'no-cors',
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
responseType: 'arraybuffer'
|
|
43
|
+
});
|
|
44
|
+
case 5:
|
|
45
|
+
response = _context.sent;
|
|
46
|
+
_context.next = 8;
|
|
47
|
+
return response.arrayBuffer();
|
|
48
|
+
case 8:
|
|
49
|
+
return _context.abrupt("return", _context.sent);
|
|
50
|
+
case 11:
|
|
51
|
+
_context.prev = 11;
|
|
52
|
+
_context.t0 = _context["catch"](2);
|
|
53
|
+
console.error(_context.t0);
|
|
54
|
+
throw _context.t0;
|
|
55
|
+
case 15:
|
|
56
|
+
case "end":
|
|
57
|
+
return _context.stop();
|
|
58
|
+
}
|
|
59
|
+
}, _callee, null, [[2, 11]]);
|
|
60
|
+
}));
|
|
61
|
+
return function postMicrosoftSpeech(_x, _x2) {
|
|
62
|
+
return _ref.apply(this, arguments);
|
|
63
|
+
};
|
|
64
|
+
}();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type StyleName = 'affectionate' | 'angry' | 'calm' | 'cheerful' | 'disgruntled' | 'embarrassed' | 'fearful' | 'general' | 'gentle' | 'sad' | 'serious';
|
|
2
|
+
export interface SsmlOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
pitch?: number;
|
|
5
|
+
rate?: number;
|
|
6
|
+
style?: StyleName;
|
|
7
|
+
}
|
|
8
|
+
export declare const genSSML: (text: string, options: SsmlOptions) => string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Document, ServiceProvider } from 'ssml-document';
|
|
2
|
+
export var genSSML = function genSSML(text, options) {
|
|
3
|
+
var ssml = new Document().voice(options.name);
|
|
4
|
+
if (options.style) ssml = ssml.expressAs({
|
|
5
|
+
style: options.style
|
|
6
|
+
});
|
|
7
|
+
if (options.pitch || options.rate) ssml = ssml.prosody({
|
|
8
|
+
pitch: options.pitch,
|
|
9
|
+
rate: options.rate
|
|
10
|
+
});
|
|
11
|
+
var result = ssml.say(text).render({
|
|
12
|
+
provider: ServiceProvider.Microsoft
|
|
13
|
+
});
|
|
14
|
+
return "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:mstts=\"https://www.w3.org/2001/mstts\">".concat(result, "</speak>");
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Voice {
|
|
2
|
+
localName?: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface VoiceList {
|
|
6
|
+
[locale: string]: Voice[];
|
|
7
|
+
}
|
|
8
|
+
export declare const genSpeechSynthesVoiceList: () => VoiceList;
|
|
9
|
+
export declare const getSpeechSynthesVoiceList: (locale?: string) => Voice[];
|
|
10
|
+
export declare const getAzureVoiceList: (locale?: string) => Voice[];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
import { flatten } from 'lodash-es';
|
|
5
|
+
import azureVoiceList from "../data/azureVoiceListLite.json";
|
|
6
|
+
export var genSpeechSynthesVoiceList = function genSpeechSynthesVoiceList() {
|
|
7
|
+
var data = speechSynthesis.getVoices();
|
|
8
|
+
var list = {};
|
|
9
|
+
var _iterator = _createForOfIteratorHelper(data),
|
|
10
|
+
_step;
|
|
11
|
+
try {
|
|
12
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
13
|
+
var voice = _step.value;
|
|
14
|
+
if (!list[voice.lang]) list[voice.lang] = [];
|
|
15
|
+
list[voice.lang].push({
|
|
16
|
+
localName: voice.name,
|
|
17
|
+
name: voice.voiceURI
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
_iterator.e(err);
|
|
22
|
+
} finally {
|
|
23
|
+
_iterator.f();
|
|
24
|
+
}
|
|
25
|
+
return list;
|
|
26
|
+
};
|
|
27
|
+
export var getSpeechSynthesVoiceList = function getSpeechSynthesVoiceList(locale) {
|
|
28
|
+
var speechSynthesVoiceList = genSpeechSynthesVoiceList();
|
|
29
|
+
if (locale) return (speechSynthesVoiceList === null || speechSynthesVoiceList === void 0 ? void 0 : speechSynthesVoiceList[locale]) || [];
|
|
30
|
+
return flatten(Object.values(speechSynthesVoiceList));
|
|
31
|
+
};
|
|
32
|
+
export var getAzureVoiceList = function getAzureVoiceList(locale) {
|
|
33
|
+
if (locale) return azureVoiceList[locale] || [];
|
|
34
|
+
return flatten(Object.values(azureVoiceList));
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.110.0",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"@react-spring/web": "^9",
|
|
82
82
|
"@react-three/drei": "^9",
|
|
83
83
|
"@react-three/fiber": "^8",
|
|
84
|
+
"@types/uuid": "^9",
|
|
84
85
|
"ahooks": "^3",
|
|
85
86
|
"chroma-js": "^2",
|
|
86
87
|
"copy-to-clipboard": "^3",
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"leva": "^0",
|
|
92
93
|
"lodash-es": "^4",
|
|
93
94
|
"lucide-react": "latest",
|
|
95
|
+
"microsoft-cognitiveservices-speech-sdk": "^1",
|
|
94
96
|
"polished": "^4",
|
|
95
97
|
"prism-react-renderer": "^2",
|
|
96
98
|
"rc-footer": "^0",
|
|
@@ -104,11 +106,13 @@
|
|
|
104
106
|
"remark-gfm": "^3",
|
|
105
107
|
"remark-math": "^5",
|
|
106
108
|
"shikiji": "^0",
|
|
109
|
+
"ssml-document": "^1",
|
|
107
110
|
"swr": "^2",
|
|
108
111
|
"three": "^0.157",
|
|
109
112
|
"ts-md5": "^1",
|
|
110
113
|
"url-join": "^5",
|
|
111
114
|
"use-merge-value": "^1",
|
|
115
|
+
"uuid": "^9",
|
|
112
116
|
"zustand": "^4.4.1",
|
|
113
117
|
"zustand-utils": "^1.3.1"
|
|
114
118
|
},
|