@charivo/tts 0.2.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.
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/web/index.ts
21
+ var web_exports = {};
22
+ __export(web_exports, {
23
+ WebTTSPlayer: () => WebTTSPlayer,
24
+ createWebTTSPlayer: () => createWebTTSPlayer
25
+ });
26
+ module.exports = __toCommonJS(web_exports);
27
+ var WebTTSPlayer = class {
28
+ playbackMode = "web-speech";
29
+ synthesis;
30
+ voices = [];
31
+ defaultVoice;
32
+ constructor() {
33
+ if (typeof window === "undefined" || !window.speechSynthesis) {
34
+ throw new Error("Web Speech API is not supported in this environment");
35
+ }
36
+ this.synthesis = window.speechSynthesis;
37
+ this.loadVoices();
38
+ }
39
+ loadVoices() {
40
+ const voices = this.synthesis.getVoices();
41
+ if (voices.length > 0) {
42
+ this.voices = voices;
43
+ } else {
44
+ this.synthesis.addEventListener("voiceschanged", () => {
45
+ this.voices = this.synthesis.getVoices();
46
+ });
47
+ }
48
+ }
49
+ findVoice(voiceId) {
50
+ return this.voices.find(
51
+ (voice) => voice.name === voiceId || voice.voiceURI === voiceId
52
+ );
53
+ }
54
+ /**
55
+ * Simple speak 메서드 (TTS Manager에서 립싱크 처리)
56
+ */
57
+ async speak(text, options) {
58
+ return new Promise((resolve, reject) => {
59
+ if (this.synthesis.speaking) {
60
+ this.synthesis.cancel();
61
+ }
62
+ const utterance = new SpeechSynthesisUtterance(text);
63
+ if (options) {
64
+ if (options.rate)
65
+ utterance.rate = Math.max(0.1, Math.min(10, options.rate));
66
+ if (options.pitch)
67
+ utterance.pitch = Math.max(0, Math.min(2, options.pitch));
68
+ if (options.volume)
69
+ utterance.volume = Math.max(0, Math.min(1, options.volume));
70
+ if (options.voice) {
71
+ const selectedVoice = this.findVoice(options.voice);
72
+ if (selectedVoice) {
73
+ utterance.voice = selectedVoice;
74
+ } else {
75
+ console.warn(`Voice "${options.voice}" not found`);
76
+ }
77
+ } else if (this.defaultVoice) {
78
+ utterance.voice = this.defaultVoice;
79
+ }
80
+ }
81
+ utterance.onend = () => resolve();
82
+ utterance.onerror = (event) => reject(new Error(`TTS Error: ${event.error}`));
83
+ this.synthesis.speak(utterance);
84
+ });
85
+ }
86
+ async stop() {
87
+ if (this.synthesis.speaking) {
88
+ this.synthesis.cancel();
89
+ }
90
+ }
91
+ setVoice(voiceId) {
92
+ const voice = this.voices.find(
93
+ (v) => v.name === voiceId || v.voiceURI === voiceId
94
+ );
95
+ if (voice) {
96
+ this.defaultVoice = voice;
97
+ } else {
98
+ console.warn(`Voice "${voiceId}" not found`);
99
+ this.defaultVoice = this.voices[0];
100
+ }
101
+ }
102
+ isSupported() {
103
+ return typeof window !== "undefined" && !!window.speechSynthesis;
104
+ }
105
+ };
106
+ function createWebTTSPlayer() {
107
+ return new WebTTSPlayer();
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ WebTTSPlayer,
112
+ createWebTTSPlayer
113
+ });
@@ -0,0 +1,87 @@
1
+ // src/web/index.ts
2
+ var WebTTSPlayer = class {
3
+ playbackMode = "web-speech";
4
+ synthesis;
5
+ voices = [];
6
+ defaultVoice;
7
+ constructor() {
8
+ if (typeof window === "undefined" || !window.speechSynthesis) {
9
+ throw new Error("Web Speech API is not supported in this environment");
10
+ }
11
+ this.synthesis = window.speechSynthesis;
12
+ this.loadVoices();
13
+ }
14
+ loadVoices() {
15
+ const voices = this.synthesis.getVoices();
16
+ if (voices.length > 0) {
17
+ this.voices = voices;
18
+ } else {
19
+ this.synthesis.addEventListener("voiceschanged", () => {
20
+ this.voices = this.synthesis.getVoices();
21
+ });
22
+ }
23
+ }
24
+ findVoice(voiceId) {
25
+ return this.voices.find(
26
+ (voice) => voice.name === voiceId || voice.voiceURI === voiceId
27
+ );
28
+ }
29
+ /**
30
+ * Simple speak 메서드 (TTS Manager에서 립싱크 처리)
31
+ */
32
+ async speak(text, options) {
33
+ return new Promise((resolve, reject) => {
34
+ if (this.synthesis.speaking) {
35
+ this.synthesis.cancel();
36
+ }
37
+ const utterance = new SpeechSynthesisUtterance(text);
38
+ if (options) {
39
+ if (options.rate)
40
+ utterance.rate = Math.max(0.1, Math.min(10, options.rate));
41
+ if (options.pitch)
42
+ utterance.pitch = Math.max(0, Math.min(2, options.pitch));
43
+ if (options.volume)
44
+ utterance.volume = Math.max(0, Math.min(1, options.volume));
45
+ if (options.voice) {
46
+ const selectedVoice = this.findVoice(options.voice);
47
+ if (selectedVoice) {
48
+ utterance.voice = selectedVoice;
49
+ } else {
50
+ console.warn(`Voice "${options.voice}" not found`);
51
+ }
52
+ } else if (this.defaultVoice) {
53
+ utterance.voice = this.defaultVoice;
54
+ }
55
+ }
56
+ utterance.onend = () => resolve();
57
+ utterance.onerror = (event) => reject(new Error(`TTS Error: ${event.error}`));
58
+ this.synthesis.speak(utterance);
59
+ });
60
+ }
61
+ async stop() {
62
+ if (this.synthesis.speaking) {
63
+ this.synthesis.cancel();
64
+ }
65
+ }
66
+ setVoice(voiceId) {
67
+ const voice = this.voices.find(
68
+ (v) => v.name === voiceId || v.voiceURI === voiceId
69
+ );
70
+ if (voice) {
71
+ this.defaultVoice = voice;
72
+ } else {
73
+ console.warn(`Voice "${voiceId}" not found`);
74
+ this.defaultVoice = this.voices[0];
75
+ }
76
+ }
77
+ isSupported() {
78
+ return typeof window !== "undefined" && !!window.speechSynthesis;
79
+ }
80
+ };
81
+ function createWebTTSPlayer() {
82
+ return new WebTTSPlayer();
83
+ }
84
+ export {
85
+ WebTTSPlayer,
86
+ createWebTTSPlayer
87
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@charivo/tts",
3
+ "version": "0.2.0",
4
+ "description": "TTS manager and browser adapters for Charivo",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./remote": {
15
+ "types": "./dist/remote/index.d.ts",
16
+ "import": "./dist/remote/index.mjs",
17
+ "require": "./dist/remote/index.js"
18
+ },
19
+ "./openai": {
20
+ "types": "./dist/openai/index.d.ts",
21
+ "import": "./dist/openai/index.mjs",
22
+ "require": "./dist/openai/index.js"
23
+ },
24
+ "./web": {
25
+ "types": "./dist/web/index.d.ts",
26
+ "import": "./dist/web/index.mjs",
27
+ "require": "./dist/web/index.js"
28
+ }
29
+ },
30
+ "keywords": [
31
+ "charivo",
32
+ "tts",
33
+ "text-to-speech",
34
+ "audio",
35
+ "lipsync"
36
+ ],
37
+ "dependencies": {
38
+ "openai": "^4.47.1",
39
+ "@charivo/core": "0.7.0"
40
+ },
41
+ "devDependencies": {
42
+ "tsup": "^8.5.0",
43
+ "typescript": "^5.9.2"
44
+ },
45
+ "peerDependencies": {},
46
+ "files": [
47
+ "dist"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "license": "MIT",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/zeikar/charivo.git",
56
+ "directory": "packages/tts"
57
+ },
58
+ "author": {
59
+ "name": "Zeikar",
60
+ "url": "https://github.com/zeikar"
61
+ },
62
+ "homepage": "https://github.com/zeikar/charivo#readme",
63
+ "bugs": {
64
+ "url": "https://github.com/zeikar/charivo/issues"
65
+ },
66
+ "scripts": {
67
+ "build": "tsup",
68
+ "dev": "tsup --watch",
69
+ "test": "vitest",
70
+ "typecheck": "tsc --noEmit"
71
+ }
72
+ }