@sefinek/google-tts-api 2.1.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/.eslintrc.js +58 -0
- package/.github/workflows/build.yml +32 -0
- package/.idea/discord.xml +7 -0
- package/.idea/google-tts-api.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +71 -0
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/assertInputTypes.d.ts +3 -0
- package/dist/assertInputTypes.d.ts.map +1 -0
- package/dist/assertInputTypes.js +18 -0
- package/dist/assertInputTypes.js.map +1 -0
- package/dist/getAudioBase64.d.ts +44 -0
- package/dist/getAudioBase64.d.ts.map +1 -0
- package/dist/getAudioBase64.js +153 -0
- package/dist/getAudioBase64.js.map +1 -0
- package/dist/getAudioUrl.d.ts +43 -0
- package/dist/getAudioUrl.d.ts.map +1 -0
- package/dist/getAudioUrl.js +71 -0
- package/dist/getAudioUrl.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/splitLongText.d.ts +17 -0
- package/dist/splitLongText.d.ts.map +1 -0
- package/dist/splitLongText.js +63 -0
- package/dist/splitLongText.js.map +1 -0
- package/package.json +45 -0
- package/tsconfig.json +73 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
'env': {
|
|
3
|
+
'es6': true,
|
|
4
|
+
'node': true,
|
|
5
|
+
'browser': true,
|
|
6
|
+
'mongo': true,
|
|
7
|
+
},
|
|
8
|
+
'extends': ['eslint:recommended'],
|
|
9
|
+
'parserOptions': {
|
|
10
|
+
'ecmaVersion': 2023,
|
|
11
|
+
},
|
|
12
|
+
'ignorePatterns': ['public/js/stella/slider.js', 'public/js/lazyload.js', 'public/js/bootstrap.bundle.min.js', 'public/js/jquery-3.7.0.min.js'],
|
|
13
|
+
'rules': {
|
|
14
|
+
'arrow-spacing': ['warn', { before: true, after: true }],
|
|
15
|
+
// 'brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
|
|
16
|
+
'comma-dangle': ['error', 'always-multiline'],
|
|
17
|
+
'comma-spacing': 'error',
|
|
18
|
+
'comma-style': 'error',
|
|
19
|
+
'curly': ['error', 'multi-line', 'consistent'],
|
|
20
|
+
'dot-location': ['error', 'property'],
|
|
21
|
+
'handle-callback-err': 'off',
|
|
22
|
+
'indent': ['warn', 'tab'],
|
|
23
|
+
'keyword-spacing': 'warn',
|
|
24
|
+
'max-nested-callbacks': ['error', { max: 4 }],
|
|
25
|
+
'max-statements-per-line': ['error', { max: 2 }],
|
|
26
|
+
'no-console': 'off',
|
|
27
|
+
'no-empty': 'warn',
|
|
28
|
+
'no-empty-function': 'error',
|
|
29
|
+
'no-floating-decimal': 'error',
|
|
30
|
+
// 'no-inline-comments': 'error',
|
|
31
|
+
'no-lonely-if': 'error',
|
|
32
|
+
'no-multi-spaces': 'warn',
|
|
33
|
+
'no-multiple-empty-lines': ['warn', { 'max': 4, 'maxEOF': 1, 'maxBOF': 0 }],
|
|
34
|
+
'no-shadow': ['error', { allow: ['err', 'resolve', 'reject'] }],
|
|
35
|
+
'no-trailing-spaces': ['warn'],
|
|
36
|
+
'no-var': 'error',
|
|
37
|
+
'object-curly-spacing': ['error', 'always'],
|
|
38
|
+
'prefer-const': 'error',
|
|
39
|
+
'quotes': ['warn', 'single'],
|
|
40
|
+
'semi': ['warn', 'always'],
|
|
41
|
+
'space-before-blocks': 'error',
|
|
42
|
+
'space-before-function-paren': ['error', {
|
|
43
|
+
anonymous: 'never',
|
|
44
|
+
named: 'never',
|
|
45
|
+
asyncArrow: 'always',
|
|
46
|
+
}],
|
|
47
|
+
'space-in-parens': 'error',
|
|
48
|
+
'space-infix-ops': 'error',
|
|
49
|
+
'space-unary-ops': 'error',
|
|
50
|
+
'spaced-comment': 'warn',
|
|
51
|
+
'yoda': 'error',
|
|
52
|
+
'no-use-before-define': ['error', { functions: false, classes: true }],
|
|
53
|
+
'no-unused-vars': 'warn',
|
|
54
|
+
'wrap-regex': 'error',
|
|
55
|
+
'sort-vars': 'warn',
|
|
56
|
+
'no-unreachable': 'warn',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
+
|
|
4
|
+
name: google-tts
|
|
5
|
+
on: [push, pull_request]
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
runs-on: ${{ matrix.os }}
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
12
|
+
node-version: [10.x, 12.x, 14.x, 15.x, 18.x, 20.x]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
16
|
+
uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: ${{ matrix.node-version }}
|
|
19
|
+
- run: npm ci
|
|
20
|
+
- run: npm run build
|
|
21
|
+
- run: npm run cover
|
|
22
|
+
- uses: coverallsapp/github-action@v2
|
|
23
|
+
with:
|
|
24
|
+
github-token: ${{ secrets.github_token }}
|
|
25
|
+
upload-code-coverage-report:
|
|
26
|
+
needs: test
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: coverallsapp/github-action@v2
|
|
30
|
+
with:
|
|
31
|
+
github-token: ${{ secrets.github_token }}
|
|
32
|
+
parallel-finished: true
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/google-tts-api.iml" filepath="$PROJECT_DIR$/.idea/google-tts-api.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
## 2.0.2 (Mar 20, 2021)
|
|
2
|
+
|
|
3
|
+
- Change default language to `en` ([#45](https://github.com/sefinek24/google-tts-api/issues/45))
|
|
4
|
+
- Typescript: Remove type `Language` since API doesn't fully support language codes listed in the document
|
|
5
|
+
|
|
6
|
+
## 2.0.1 (Jan 6, 2021)
|
|
7
|
+
|
|
8
|
+
- Fix the vulnerabilities by upgrading the dependencies (#42, #44)
|
|
9
|
+
|
|
10
|
+
## 2.0.0 (Dec 8, 2020)
|
|
11
|
+
|
|
12
|
+
- Add new APIs (Please see the **Break Change** below)
|
|
13
|
+
|
|
14
|
+
| Method | Options (optional) | Return Type | Handle Long Text |
|
|
15
|
+
|---------------------|-------------------------------------------------|-----------------------------------------------------|:----------------:|
|
|
16
|
+
| `getAudioUrl` | `lang`, `slow`, `host` | `string` | |
|
|
17
|
+
| `getAudioBase64` | `lang`, `slow`, `host`, `timeout` | `Promise<string>` | |
|
|
18
|
+
| `getAllAudioUrls` | `lang`, `slow`, `host`, `splitPunct` | `{ shortText: string; url: string; }[]` | ✅ |
|
|
19
|
+
| `getAllAudioBase64` | `lang`, `slow`, `host`, `timeout`, `splitPunct` | `Promise<{ shortText: string; base64: string; }[]>` | ✅ |
|
|
20
|
+
|
|
21
|
+
- Support new Google TTS API to get audio Base64 text ([#35](https://github.com/sefinek24/google-tts-api/issues/35))
|
|
22
|
+
- Support long text input: `getAllAudioUrls` and `getAllAudioBase64` ([#30](https://github.com/sefinek24/google-tts-api/issues/30))
|
|
23
|
+
- Support changing the `host` in option ([#16](https://github.com/sefinek24/google-tts-api/issues/16))
|
|
24
|
+
- Support Typescript
|
|
25
|
+
- Add dependency [axios](https://github.com/axios/axios)
|
|
26
|
+
|
|
27
|
+
### **Break Change from 0.x.x to 2.x.x**
|
|
28
|
+
|
|
29
|
+
`googleTTS()` is changed to `googleTTS.getAudioUrl()`.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const googleTTS = require('google-tts-api');
|
|
33
|
+
|
|
34
|
+
// Before version 0.0.6
|
|
35
|
+
// Original googleTTS is a promise function
|
|
36
|
+
const url = await googleTTS('Hello World', 'en', 1);
|
|
37
|
+
|
|
38
|
+
// After version 2.0.0
|
|
39
|
+
// Now googleTTS is an object with 4 new methods (getAudioUrl, getAudioBase64, getAllAudioUrls, getAllAudioBase64)
|
|
40
|
+
// googleTTS.getAudioUrl is a non-promise function
|
|
41
|
+
const url = googleTTS.getAudioUrl('Hello World', {
|
|
42
|
+
lang: 'en-US',
|
|
43
|
+
slow: false, // speed (number) is changed to slow (boolean)
|
|
44
|
+
host: 'https://translate.google.com', // allow to change the host
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 0.0.6 (Dec 5, 2020)
|
|
49
|
+
|
|
50
|
+
- `timeout` parameter is deprecated.
|
|
51
|
+
- Remove dependency `isomorphic-fetch`.
|
|
52
|
+
- Fix the change of Google Translate API ([@freddiefujiwara](https://github.com/freddiefujiwara) in [#37](https://github.com/sefinek24/google-tts-api/pull/37)). Read more in [#35](https://github.com/sefinek24/google-tts-api/issues/35)
|
|
53
|
+
|
|
54
|
+
## 0.0.5 (Nov 8, 2020)
|
|
55
|
+
|
|
56
|
+
- Upgrade the dependencies and fix the vulnerability. ([#32](https://github.com/sefinek24/google-tts-api/issues/32))
|
|
57
|
+
- Add retry mechanism to prevent fetching token key failed too frequently. ([#33](https://github.com/sefinek24/google-tts-api/issues/33))
|
|
58
|
+
|
|
59
|
+
## 0.0.4 (Nov 29, 2018)
|
|
60
|
+
|
|
61
|
+
- Fix the change of Google Translate API ([@ncpierson](https://github.com/ncpierson) in [#19](https://github.com/sefinek24/google-tts-api/pull/19))
|
|
62
|
+
|
|
63
|
+
## 0.0.3 (Sep 21, 2018)
|
|
64
|
+
|
|
65
|
+
- Add package-lock.lock file
|
|
66
|
+
- Fix the change of Google Translate API ([@ncpierson](https://github.com/ncpierson) in [#14](https://github.com/sefinek24/google-tts-api/pull/14))
|
|
67
|
+
|
|
68
|
+
## 0.0.2 (Aug 25, 2017)
|
|
69
|
+
|
|
70
|
+
- Add yarn.lock file
|
|
71
|
+
- If length of input text is over than 200 characters, throw a `RangeError` with error message. ([#5](https://github.com/sefinek24/google-tts-api/issues/5))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Leon Huang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @sefinek/google-tts-api
|
|
2
|
+
Google TTS (Text-To-Speech) for Node.js without any vulnerabilities.
|
|
3
|
+
|
|
4
|
+
[![][npm-img]][npm-url]
|
|
5
|
+
|
|
6
|
+
[![][dependency-img]][dependency-url]
|
|
7
|
+
[![][dependency-dev-img]][dependency-dev-url]
|
|
8
|
+
[![][install-size-img]][install-size-result]
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
```bash
|
|
12
|
+
$ npm install --save google-tts-api
|
|
13
|
+
$ npm install -D typescript @types/node # Only for TypeScript
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Change Log
|
|
17
|
+
[CHANGELOG.md](https://github.com/sefinek24/google-tts-api/blob/master/CHANGELOG.md)
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
| Method | Options (all optional) | Return Type | Handle Long Text |
|
|
21
|
+
|---------------------|-------------------------------------------------|-----------------------------------------------------|:----------------:|
|
|
22
|
+
| `getAudioUrl` | `lang`, `slow`, `host` | `string` | |
|
|
23
|
+
| `getAudioBase64` | `lang`, `slow`, `host`, `timeout` | `Promise<string>` | |
|
|
24
|
+
| `getAllAudioUrls` | `lang`, `slow`, `host`, `splitPunct` | `{ shortText: string; url: string; }[]` | ✅ |
|
|
25
|
+
| `getAllAudioBase64` | `lang`, `slow`, `host`, `timeout`, `splitPunct` | `Promise<{ shortText: string; base64: string; }[]>` | ✅ |
|
|
26
|
+
|
|
27
|
+
### Options (all optional)
|
|
28
|
+
| Option | Type | Default | Description |
|
|
29
|
+
|--------------|-----------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
|
|
30
|
+
| `lang` | `string` | en | See all available language code at https://cloud.google.com/speech/docs/languages |
|
|
31
|
+
| `slow` | `boolean` | false | Use the slow audio speed if set `slow` to `true` |
|
|
32
|
+
| `host` | `string` | https://translate.google.com | You can change the `host` if the default host could not work in your region (e.g. https://translate.google.com.cn). |
|
|
33
|
+
| `timeout` | `number` | 10000 (ms) | (Only for `getAudioBase64` and `getAllAudioBase64`) Set timeout for the HTTP request. |
|
|
34
|
+
| `splitPunct` | `string` | | (Only for `getAllAudioUrls` and `getAllAudioBase64`) Set the punctuation to split the long text to short text. (e.g. ",、。") |
|
|
35
|
+
|
|
36
|
+
## Examples
|
|
37
|
+
### 1. `getAudioUrl(text, [option])`
|
|
38
|
+
```js
|
|
39
|
+
import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
|
|
40
|
+
const googleTTS = require('google-tts-api'); // CommonJS
|
|
41
|
+
|
|
42
|
+
// get audio URL
|
|
43
|
+
const url = googleTTS.getAudioUrl('Hello World', {
|
|
44
|
+
lang: 'en',
|
|
45
|
+
slow: false,
|
|
46
|
+
host: 'https://translate.google.com',
|
|
47
|
+
});
|
|
48
|
+
console.log(url); // https://translate.google.com/translate_tts?...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. `getAudioBase64(text, [option])`
|
|
52
|
+
```js
|
|
53
|
+
import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
|
|
54
|
+
const googleTTS = require('google-tts-api'); // CommonJS
|
|
55
|
+
|
|
56
|
+
// get base64 text
|
|
57
|
+
googleTTS
|
|
58
|
+
.getAudioBase64('Hello World', {
|
|
59
|
+
lang: 'en',
|
|
60
|
+
slow: false,
|
|
61
|
+
host: 'https://translate.google.com',
|
|
62
|
+
timeout: 10000,
|
|
63
|
+
})
|
|
64
|
+
.then(console.log) // base64 text
|
|
65
|
+
.catch(console.error);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. `getAllAudioUrls(text, [option])` (For text longer than 200 characters)
|
|
69
|
+
```js
|
|
70
|
+
import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
|
|
71
|
+
const googleTTS = require('google-tts-api'); // CommonJS
|
|
72
|
+
|
|
73
|
+
const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
|
|
74
|
+
lang: 'en',
|
|
75
|
+
slow: false,
|
|
76
|
+
host: 'https://translate.google.com',
|
|
77
|
+
splitPunct: ',.?',
|
|
78
|
+
});
|
|
79
|
+
console.log(results);
|
|
80
|
+
// [
|
|
81
|
+
// { shortText: '...', url: '...' },
|
|
82
|
+
// { shortText: '...', url: '...' },
|
|
83
|
+
// ...
|
|
84
|
+
// ];
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 4. `getAllAudioBase64(text, [option])` (For text longer than 200 characters)
|
|
88
|
+
```js
|
|
89
|
+
import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
|
|
90
|
+
const googleTTS = require('google-tts-api'); // CommonJS
|
|
91
|
+
|
|
92
|
+
googleTTS
|
|
93
|
+
.getAllAudioBase64('LONG_TEXT_...', {
|
|
94
|
+
lang: 'en',
|
|
95
|
+
slow: false,
|
|
96
|
+
host: 'https://translate.google.com',
|
|
97
|
+
timeout: 10000,
|
|
98
|
+
splitPunct: ',.?',
|
|
99
|
+
})
|
|
100
|
+
.then(console.log)
|
|
101
|
+
// [
|
|
102
|
+
// { shortText: '...', base64: '...' },
|
|
103
|
+
// { shortText: '...', base64: '...' },
|
|
104
|
+
// ...
|
|
105
|
+
// ];
|
|
106
|
+
.catch(console.error);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
[More Examples](https://github.com/sefinek24/google-tts-api/tree/master/example)
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
MIT
|
|
113
|
+
|
|
114
|
+
[npm-url]: https://nodei.co/npm/google-tts-api
|
|
115
|
+
[npm-img]: https://nodei.co/npm/google-tts-api.png
|
|
116
|
+
[install-size-img]: https://packagephobia.com/badge?p=google-tts-api
|
|
117
|
+
[install-size-result]: https://packagephobia.com/result?p=google-tts-api
|
|
118
|
+
[dependency-url]: https://david-dm.org/sefinek24/google-tts-api
|
|
119
|
+
[dependency-img]: https://img.shields.io/david/sefinek24/google-tts-api.svg
|
|
120
|
+
[dependency-dev-url]: https://david-dm.org/sefinek24/google-tts-api#info=devDependencies
|
|
121
|
+
[dependency-dev-img]: https://img.shields.io/david/dev/sefinek24/google-tts-api.svg
|
|
122
|
+
[gh-action-url]: https://github.com/sefinek24/google-tts-api/actions
|
|
123
|
+
[gh-action-img]: https://github.com/sefinek24/google-tts-api/actions/workflows/build.yml/badge.svg
|
|
124
|
+
[coverage-url]: https://coveralls.io/github/sefinek24/google-tts-api
|
|
125
|
+
[coverage-img]: https://img.shields.io/coveralls/github/sefinek24/google-tts-api
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertInputTypes.d.ts","sourceRoot":"","sources":["../src/assertInputTypes.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,SAAU,MAAM,QAAQ,MAAM,QAAQ,OAAO,QAAQ,MAAM,SAgBhF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var assertInputTypes = function (text, lang, slow, host) {
|
|
4
|
+
if (typeof text !== 'string' || text.length === 0) {
|
|
5
|
+
throw new TypeError('text should be a string');
|
|
6
|
+
}
|
|
7
|
+
if (typeof lang !== 'string' || lang.length === 0) {
|
|
8
|
+
throw new TypeError('lang should be a string');
|
|
9
|
+
}
|
|
10
|
+
if (typeof slow !== 'boolean') {
|
|
11
|
+
throw new TypeError('slow should be a boolean');
|
|
12
|
+
}
|
|
13
|
+
if (typeof host !== 'string' || host.length === 0) {
|
|
14
|
+
throw new TypeError('host should be a string');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.default = assertInputTypes;
|
|
18
|
+
//# sourceMappingURL=assertInputTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertInputTypes.js","sourceRoot":"","sources":["../src/assertInputTypes.ts"],"names":[],"mappings":";;AAAA,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAE,IAAY,EAAE,IAAa,EAAE,IAAY;IAC/E,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;IACjD,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface Option {
|
|
2
|
+
lang?: string;
|
|
3
|
+
slow?: boolean;
|
|
4
|
+
host?: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get "Google TTS" audio base64 text
|
|
9
|
+
*
|
|
10
|
+
* @param {string} text length should be less than 200 characters
|
|
11
|
+
* @param {object?} option
|
|
12
|
+
* @param {string?} option.lang default is "en"
|
|
13
|
+
* @param {boolean?} option.slow default is false
|
|
14
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
15
|
+
* @param {number?} option.timeout default is 10000 (ms)
|
|
16
|
+
* @returns {Promise<string>} url
|
|
17
|
+
*/
|
|
18
|
+
export declare const getAudioBase64: (text: string, { lang, slow, host, timeout }?: Option) => Promise<string>;
|
|
19
|
+
interface LongTextOption extends Option {
|
|
20
|
+
splitPunct?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} Result
|
|
24
|
+
* @property {string} shortText
|
|
25
|
+
* @property {string} base64
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Split the long text into multiple short text and generate audio base64 list
|
|
29
|
+
*
|
|
30
|
+
* @param {string} text
|
|
31
|
+
* @param {object?} option
|
|
32
|
+
* @param {string?} option.lang default is "en"
|
|
33
|
+
* @param {boolean?} option.slow default is false
|
|
34
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
35
|
+
* @param {string?} option.splitPunct split punctuation
|
|
36
|
+
* @param {number?} option.timeout default is 10000 (ms)
|
|
37
|
+
* @return {Result[]} the list with short text and audio base64
|
|
38
|
+
*/
|
|
39
|
+
export declare const getAllAudioBase64: (text: string, { lang, slow, host, splitPunct, timeout, }?: LongTextOption) => Promise<{
|
|
40
|
+
shortText: string;
|
|
41
|
+
base64: string;
|
|
42
|
+
}[]>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=getAudioBase64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAudioBase64.d.ts","sourceRoot":"","sources":["../src/getAudioBase64.ts"],"names":[],"mappings":"AAIA,UAAU,MAAM;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,SACjB,MAAM,kCAC2E,MAAM,KAC9F,QAAQ,MAAM,CAgDhB,CAAC;AAEF,UAAU,cAAe,SAAQ,MAAM;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,SACpB,MAAM,+CAOT,cAAc,KAClB,QAAQ;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CAyBjD,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getAllAudioBase64 = exports.getAudioBase64 = void 0;
|
|
43
|
+
var assertInputTypes_1 = __importDefault(require("./assertInputTypes"));
|
|
44
|
+
var axios_1 = __importDefault(require("axios"));
|
|
45
|
+
var splitLongText_1 = __importDefault(require("./splitLongText"));
|
|
46
|
+
/**
|
|
47
|
+
* Get "Google TTS" audio base64 text
|
|
48
|
+
*
|
|
49
|
+
* @param {string} text length should be less than 200 characters
|
|
50
|
+
* @param {object?} option
|
|
51
|
+
* @param {string?} option.lang default is "en"
|
|
52
|
+
* @param {boolean?} option.slow default is false
|
|
53
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
54
|
+
* @param {number?} option.timeout default is 10000 (ms)
|
|
55
|
+
* @returns {Promise<string>} url
|
|
56
|
+
*/
|
|
57
|
+
var getAudioBase64 = function (text, _a) {
|
|
58
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.lang, lang = _c === void 0 ? 'en' : _c, _d = _b.slow, slow = _d === void 0 ? false : _d, _e = _b.host, host = _e === void 0 ? 'https://translate.google.com' : _e, _f = _b.timeout, timeout = _f === void 0 ? 10000 : _f;
|
|
59
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var res, result;
|
|
61
|
+
return __generator(this, function (_g) {
|
|
62
|
+
switch (_g.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
(0, assertInputTypes_1.default)(text, lang, slow, host);
|
|
65
|
+
if (typeof timeout !== 'number' || timeout <= 0) {
|
|
66
|
+
throw new TypeError('timeout should be a positive number');
|
|
67
|
+
}
|
|
68
|
+
if (text.length > 200) {
|
|
69
|
+
throw new RangeError("text length (".concat(text.length, ") should be less than 200 characters. Try \"getAllAudioBase64(text, [option])\" for long text."));
|
|
70
|
+
}
|
|
71
|
+
return [4 /*yield*/, (0, axios_1.default)({
|
|
72
|
+
method: 'post',
|
|
73
|
+
baseURL: host,
|
|
74
|
+
url: '/_/TranslateWebserverUi/data/batchexecute',
|
|
75
|
+
timeout: timeout,
|
|
76
|
+
data: 'f.req=' +
|
|
77
|
+
encodeURIComponent(JSON.stringify([
|
|
78
|
+
[['jQ1olc', JSON.stringify([text, lang, slow ? true : null, 'null']), null, 'generic']],
|
|
79
|
+
])),
|
|
80
|
+
})];
|
|
81
|
+
case 1:
|
|
82
|
+
res = _g.sent();
|
|
83
|
+
try {
|
|
84
|
+
result = eval(res.data.slice(5))[0][2];
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new Error("parse response failed:\n".concat(res.data));
|
|
88
|
+
}
|
|
89
|
+
// Check the result. The result will be null if given the lang doesn't exist
|
|
90
|
+
if (!result) {
|
|
91
|
+
throw new Error("lang \"".concat(lang, "\" might not exist"));
|
|
92
|
+
}
|
|
93
|
+
// 2. continue to parse audio base64 string
|
|
94
|
+
try {
|
|
95
|
+
result = eval(result)[0];
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
throw new Error("parse response failed:\n".concat(res.data));
|
|
99
|
+
}
|
|
100
|
+
return [2 /*return*/, result];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
exports.getAudioBase64 = getAudioBase64;
|
|
106
|
+
/**
|
|
107
|
+
* @typedef {object} Result
|
|
108
|
+
* @property {string} shortText
|
|
109
|
+
* @property {string} base64
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Split the long text into multiple short text and generate audio base64 list
|
|
113
|
+
*
|
|
114
|
+
* @param {string} text
|
|
115
|
+
* @param {object?} option
|
|
116
|
+
* @param {string?} option.lang default is "en"
|
|
117
|
+
* @param {boolean?} option.slow default is false
|
|
118
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
119
|
+
* @param {string?} option.splitPunct split punctuation
|
|
120
|
+
* @param {number?} option.timeout default is 10000 (ms)
|
|
121
|
+
* @return {Result[]} the list with short text and audio base64
|
|
122
|
+
*/
|
|
123
|
+
var getAllAudioBase64 = function (text, _a) {
|
|
124
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.lang, lang = _c === void 0 ? 'en' : _c, _d = _b.slow, slow = _d === void 0 ? false : _d, _e = _b.host, host = _e === void 0 ? 'https://translate.google.com' : _e, _f = _b.splitPunct, splitPunct = _f === void 0 ? '' : _f, _g = _b.timeout, timeout = _g === void 0 ? 10000 : _g;
|
|
125
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var shortTextList, base64List, result, i, shortText, base64;
|
|
127
|
+
return __generator(this, function (_h) {
|
|
128
|
+
switch (_h.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
(0, assertInputTypes_1.default)(text, lang, slow, host);
|
|
131
|
+
if (typeof splitPunct !== 'string') {
|
|
132
|
+
throw new TypeError('splitPunct should be a string');
|
|
133
|
+
}
|
|
134
|
+
if (typeof timeout !== 'number' || timeout <= 0) {
|
|
135
|
+
throw new TypeError('timeout should be a positive number');
|
|
136
|
+
}
|
|
137
|
+
shortTextList = (0, splitLongText_1.default)(text, { splitPunct: splitPunct });
|
|
138
|
+
return [4 /*yield*/, Promise.all(shortTextList.map(function (shortText) { return (0, exports.getAudioBase64)(shortText, { lang: lang, slow: slow, host: host, timeout: timeout }); }))];
|
|
139
|
+
case 1:
|
|
140
|
+
base64List = _h.sent();
|
|
141
|
+
result = [];
|
|
142
|
+
for (i = 0; i < shortTextList.length; i++) {
|
|
143
|
+
shortText = shortTextList[i];
|
|
144
|
+
base64 = base64List[i];
|
|
145
|
+
result.push({ shortText: shortText, base64: base64 });
|
|
146
|
+
}
|
|
147
|
+
return [2 /*return*/, result];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
exports.getAllAudioBase64 = getAllAudioBase64;
|
|
153
|
+
//# sourceMappingURL=getAudioBase64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAudioBase64.js","sourceRoot":"","sources":["../src/getAudioBase64.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import url from 'url';
|
|
3
|
+
interface Option {
|
|
4
|
+
lang?: string;
|
|
5
|
+
slow?: boolean;
|
|
6
|
+
host?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generate "Google TTS" audio URL
|
|
10
|
+
*
|
|
11
|
+
* @param {string} text length should be less than 200 characters
|
|
12
|
+
* @param {object?} option
|
|
13
|
+
* @param {string?} option.lang default is "en"
|
|
14
|
+
* @param {boolean?} option.slow default is false
|
|
15
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
16
|
+
* @return {string} url
|
|
17
|
+
*/
|
|
18
|
+
export declare const getAudioUrl: (text: string, { lang, slow, host }?: Option) => string;
|
|
19
|
+
interface LongTextOption extends Option {
|
|
20
|
+
splitPunct?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} Result
|
|
24
|
+
* @property {string} shortText
|
|
25
|
+
* @property {string} url
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Split the long text into multiple short text and generate audio URL list
|
|
29
|
+
*
|
|
30
|
+
* @param {string} text
|
|
31
|
+
* @param {object?} option
|
|
32
|
+
* @param {string?} option.lang default is "en"
|
|
33
|
+
* @param {boolean?} option.slow default is false
|
|
34
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
35
|
+
* @param {string?} option.splitPunct split punctuation
|
|
36
|
+
* @return {Result[]} the list with short text and audio url
|
|
37
|
+
*/
|
|
38
|
+
export declare const getAllAudioUrls: (text: string, { lang, slow, host, splitPunct, }?: LongTextOption) => {
|
|
39
|
+
shortText: string;
|
|
40
|
+
url: string;
|
|
41
|
+
}[];
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=getAudioUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAudioUrl.d.ts","sourceRoot":"","sources":["../src/getAudioUrl.ts"],"names":[],"mappings":";AAEA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,UAAU,MAAM;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,SACd,MAAM,yBAC0D,MAAM,KAC7E,MA0BF,CAAC;AAEF,UAAU,cAAe,SAAQ,MAAM;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,SAClB,MAAM,sCAMT,cAAc,KAClB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,MAAM,CAAA;CAAE,EAWpC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAllAudioUrls = exports.getAudioUrl = void 0;
|
|
7
|
+
var assertInputTypes_1 = __importDefault(require("./assertInputTypes"));
|
|
8
|
+
var splitLongText_1 = __importDefault(require("./splitLongText"));
|
|
9
|
+
var url_1 = __importDefault(require("url"));
|
|
10
|
+
/**
|
|
11
|
+
* Generate "Google TTS" audio URL
|
|
12
|
+
*
|
|
13
|
+
* @param {string} text length should be less than 200 characters
|
|
14
|
+
* @param {object?} option
|
|
15
|
+
* @param {string?} option.lang default is "en"
|
|
16
|
+
* @param {boolean?} option.slow default is false
|
|
17
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
18
|
+
* @return {string} url
|
|
19
|
+
*/
|
|
20
|
+
var getAudioUrl = function (text, _a) {
|
|
21
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.lang, lang = _c === void 0 ? 'en' : _c, _d = _b.slow, slow = _d === void 0 ? false : _d, _e = _b.host, host = _e === void 0 ? 'https://translate.google.com' : _e;
|
|
22
|
+
(0, assertInputTypes_1.default)(text, lang, slow, host);
|
|
23
|
+
if (text.length > 200) {
|
|
24
|
+
throw new RangeError("text length (".concat(text.length, ") should be less than 200 characters. Try \"getAllAudioUrls(text, [option])\" for long text."));
|
|
25
|
+
}
|
|
26
|
+
return (host +
|
|
27
|
+
'/translate_tts' +
|
|
28
|
+
url_1.default.format({
|
|
29
|
+
query: {
|
|
30
|
+
ie: 'UTF-8',
|
|
31
|
+
q: text,
|
|
32
|
+
tl: lang,
|
|
33
|
+
total: 1,
|
|
34
|
+
idx: 0,
|
|
35
|
+
textlen: text.length,
|
|
36
|
+
client: 'tw-ob',
|
|
37
|
+
prev: 'input',
|
|
38
|
+
ttsspeed: slow ? 0.24 : 1,
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
exports.getAudioUrl = getAudioUrl;
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {object} Result
|
|
45
|
+
* @property {string} shortText
|
|
46
|
+
* @property {string} url
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Split the long text into multiple short text and generate audio URL list
|
|
50
|
+
*
|
|
51
|
+
* @param {string} text
|
|
52
|
+
* @param {object?} option
|
|
53
|
+
* @param {string?} option.lang default is "en"
|
|
54
|
+
* @param {boolean?} option.slow default is false
|
|
55
|
+
* @param {string?} option.host default is "https://translate.google.com"
|
|
56
|
+
* @param {string?} option.splitPunct split punctuation
|
|
57
|
+
* @return {Result[]} the list with short text and audio url
|
|
58
|
+
*/
|
|
59
|
+
var getAllAudioUrls = function (text, _a) {
|
|
60
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.lang, lang = _c === void 0 ? 'en' : _c, _d = _b.slow, slow = _d === void 0 ? false : _d, _e = _b.host, host = _e === void 0 ? 'https://translate.google.com' : _e, _f = _b.splitPunct, splitPunct = _f === void 0 ? '' : _f;
|
|
61
|
+
(0, assertInputTypes_1.default)(text, lang, slow, host);
|
|
62
|
+
if (typeof splitPunct !== 'string') {
|
|
63
|
+
throw new TypeError('splitPunct should be a string');
|
|
64
|
+
}
|
|
65
|
+
return (0, splitLongText_1.default)(text, { splitPunct: splitPunct }).map(function (shortText) { return ({
|
|
66
|
+
shortText: shortText,
|
|
67
|
+
url: (0, exports.getAudioUrl)(shortText, { lang: lang, slow: slow, host: host }),
|
|
68
|
+
}); });
|
|
69
|
+
};
|
|
70
|
+
exports.getAllAudioUrls = getAllAudioUrls;
|
|
71
|
+
//# sourceMappingURL=getAudioUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAudioUrl.js","sourceRoot":"","sources":["../src/getAudioUrl.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAkD;AAClD,kEAA4C;AAC5C,4CAAsB;AAQtB;;;;;;;;;GASG;AACI,IAAM,WAAW,GAAG,UACvB,IAAY,EACZ,EAAiF;QAAjF,qBAA+E,EAAE,KAAA,EAA/E,YAAW,EAAX,IAAI,mBAAG,IAAI,KAAA,EAAE,YAAY,EAAZ,IAAI,mBAAG,KAAK,KAAA,EAAE,YAAqC,EAArC,IAAI,mBAAG,8BAA8B,KAAA;IAEpE,IAAA,0BAAgB,EAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAEzC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtB,MAAM,IAAI,UAAU,CAChB,uBAAgB,IAAI,CAAC,MAAM,iGAA4F,CAC1H,CAAC;IACJ,CAAC;IAED,OAAO,CACH,IAAI;QACJ,gBAAgB;QAChB,aAAG,CAAC,MAAM,CAAC;YACT,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,CAAC,EAAE,IAAI;gBACP,EAAE,EAAE,IAAI;gBACR,KAAK,EAAE,CAAC;gBACR,GAAG,EAAE,CAAC;gBACN,OAAO,EAAE,IAAI,CAAC,MAAM;gBACpB,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aAC1B;SACF,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,WAAW,eA6BtB;AAMF;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACI,IAAM,eAAe,GAAG,UAC3B,IAAY,EACZ,EAKsB;QALtB,qBAKoB,EAAE,KAAA,EAJpB,YAAW,EAAX,IAAI,mBAAG,IAAI,KAAA,EACX,YAAY,EAAZ,IAAI,mBAAG,KAAK,KAAA,EACZ,YAAqC,EAArC,IAAI,mBAAG,8BAA8B,KAAA,EACrC,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA;IAGnB,IAAA,0BAAgB,EAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAEzC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAA,uBAAa,EAAC,IAAI,EAAE,EAAE,UAAU,YAAA,EAAE,CAAC,CAAC,GAAG,CAAC,UAAC,SAAS,IAAK,OAAA,CAAC;QAC7D,SAAS,WAAA;QACT,GAAG,EAAE,IAAA,mBAAW,EAAC,SAAS,EAAE,EAAE,IAAI,MAAA,EAAE,IAAI,MAAA,EAAE,IAAI,MAAA,EAAE,CAAC;KAClD,CAAC,EAH4D,CAG5D,CAAC,CAAC;AACN,CAAC,CAAC;AAnBW,QAAA,eAAe,mBAmB1B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllAudioBase64 = exports.getAudioBase64 = exports.getAllAudioUrls = exports.getAudioUrl = void 0;
|
|
4
|
+
var getAudioUrl_1 = require("./getAudioUrl");
|
|
5
|
+
Object.defineProperty(exports, "getAudioUrl", { enumerable: true, get: function () { return getAudioUrl_1.getAudioUrl; } });
|
|
6
|
+
Object.defineProperty(exports, "getAllAudioUrls", { enumerable: true, get: function () { return getAudioUrl_1.getAllAudioUrls; } });
|
|
7
|
+
var getAudioBase64_1 = require("./getAudioBase64");
|
|
8
|
+
Object.defineProperty(exports, "getAudioBase64", { enumerable: true, get: function () { return getAudioBase64_1.getAudioBase64; } });
|
|
9
|
+
Object.defineProperty(exports, "getAllAudioBase64", { enumerable: true, get: function () { return getAudioBase64_1.getAllAudioBase64; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6D;AAGpD,4FAHA,yBAAW,OAGA;AAAE,gGAHA,6BAAe,OAGA;AAFrC,mDAAqE;AAE9B,+FAF9B,+BAAc,OAE8B;AAAE,kGAF9B,kCAAiB,OAE8B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Option {
|
|
2
|
+
maxLength?: number;
|
|
3
|
+
splitPunct?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* split the long text to short texts
|
|
7
|
+
* Time Complexity: O(n)
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text
|
|
10
|
+
* @param {object?} option
|
|
11
|
+
* @param {number?} option.maxLength default is 200
|
|
12
|
+
* @param {string?} option.splitPunct default is ''
|
|
13
|
+
* @returns {string[]} short text list
|
|
14
|
+
*/
|
|
15
|
+
declare const splitLongText: (text: string, { maxLength, splitPunct }?: Option) => string[];
|
|
16
|
+
export default splitLongText;
|
|
17
|
+
//# sourceMappingURL=splitLongText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitLongText.d.ts","sourceRoot":"","sources":["../src/splitLongText.ts"],"names":[],"mappings":"AAMA,UAAU,MAAM;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,QAAA,MAAM,aAAa,SACT,MAAM,8BAC0B,MAAM,KAC7C,MAAM,EAmDR,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
|
|
4
|
+
var SPACE_REGEX = '\\s\\uFEFF\\xA0';
|
|
5
|
+
// https://remarkablemark.org/blog/2019/09/28/javascript-remove-punctuation/
|
|
6
|
+
var DEFAULT_PUNCTUATION_REGEX = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
|
|
7
|
+
/**
|
|
8
|
+
* split the long text to short texts
|
|
9
|
+
* Time Complexity: O(n)
|
|
10
|
+
*
|
|
11
|
+
* @param {string} text
|
|
12
|
+
* @param {object?} option
|
|
13
|
+
* @param {number?} option.maxLength default is 200
|
|
14
|
+
* @param {string?} option.splitPunct default is ''
|
|
15
|
+
* @returns {string[]} short text list
|
|
16
|
+
*/
|
|
17
|
+
var splitLongText = function (text, _a) {
|
|
18
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.maxLength, maxLength = _c === void 0 ? 200 : _c, _d = _b.splitPunct, splitPunct = _d === void 0 ? '' : _d;
|
|
19
|
+
var isSpaceOrPunct = function (s, i) {
|
|
20
|
+
var regex = new RegExp('[' + SPACE_REGEX + DEFAULT_PUNCTUATION_REGEX + splitPunct + ']');
|
|
21
|
+
return regex.test(s.charAt(i));
|
|
22
|
+
};
|
|
23
|
+
var lastIndexOfSpaceOrPunct = function (s, left, right) {
|
|
24
|
+
for (var i = right; i >= left; i--) {
|
|
25
|
+
if (isSpaceOrPunct(s, i))
|
|
26
|
+
return i;
|
|
27
|
+
}
|
|
28
|
+
return -1; // not found
|
|
29
|
+
};
|
|
30
|
+
var result = [];
|
|
31
|
+
var addResult = function (text, start, end) {
|
|
32
|
+
result.push(text.slice(start, end + 1));
|
|
33
|
+
};
|
|
34
|
+
var start = 0;
|
|
35
|
+
for (;;) {
|
|
36
|
+
// check text's length
|
|
37
|
+
if (text.length - start <= maxLength) {
|
|
38
|
+
addResult(text, start, text.length - 1);
|
|
39
|
+
break; // end of text
|
|
40
|
+
}
|
|
41
|
+
// check whether the word is cut in the middle.
|
|
42
|
+
var end = start + maxLength - 1;
|
|
43
|
+
if (isSpaceOrPunct(text, end) || isSpaceOrPunct(text, end + 1)) {
|
|
44
|
+
addResult(text, start, end);
|
|
45
|
+
start = end + 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// find last index of space
|
|
49
|
+
end = lastIndexOfSpaceOrPunct(text, start, end);
|
|
50
|
+
if (end === -1) {
|
|
51
|
+
var str = text.slice(start, start + maxLength);
|
|
52
|
+
throw new Error('The word is too long to split into a short text:' +
|
|
53
|
+
"\n".concat(str, " ...") +
|
|
54
|
+
'\n\nTry the option "splitPunct" to split the text by punctuation.');
|
|
55
|
+
}
|
|
56
|
+
// add result
|
|
57
|
+
addResult(text, start, end);
|
|
58
|
+
start = end + 1;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
exports.default = splitLongText;
|
|
63
|
+
//# sourceMappingURL=splitLongText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitLongText.js","sourceRoot":"","sources":["../src/splitLongText.ts"],"names":[],"mappings":";;AAAA,+FAA+F;AAC/F,IAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,4EAA4E;AAC5E,IAAM,yBAAyB,GAAG,oCAAoC,CAAC;AAOvE;;;;;;;;;GASG;AACH,IAAM,aAAa,GAAG,UAClB,IAAY,EACZ,EAAiD;QAAjD,qBAA+C,EAAE,KAAA,EAA/C,iBAAe,EAAf,SAAS,mBAAG,GAAG,KAAA,EAAE,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA;IAEpC,IAAM,cAAc,GAAG,UAAC,CAAS,EAAE,CAAS;QAC1C,IAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,WAAW,GAAG,yBAAyB,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC;QAC3F,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,IAAM,uBAAuB,GAAG,UAAC,CAAS,EAAE,IAAY,EAAE,KAAa;QACrE,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY;IACzB,CAAC,CAAC;IAEF,IAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAM,SAAS,GAAG,UAAC,IAAY,EAAE,KAAa,EAAE,GAAW;QACzD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEF,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,SAAS,CAAC;QACR,sBAAsB;QACtB,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,SAAS,EAAE,CAAC;YACrC,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACxC,MAAM,CAAC,cAAc;QACvB,CAAC;QAED,+CAA+C;QAC/C,IAAI,GAAG,GAAG,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC;QAChC,IAAI,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/D,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC5B,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC;YAChB,SAAS;QACX,CAAC;QAED,2BAA2B;QAC3B,GAAG,GAAG,uBAAuB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAChD,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;YACjD,MAAM,IAAI,KAAK,CACX,kDAAkD;gBAClD,YAAK,GAAG,SAAM;gBACd,mEAAmE,CACtE,CAAC;QACJ,CAAC;QAED,aAAa;QACb,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC5B,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sefinek/google-tts-api",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Google TTS (Text-To-Speech) for node.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -p .",
|
|
8
|
+
"test": "npm run build && jest",
|
|
9
|
+
"cover": "npm run build && jest --coverage",
|
|
10
|
+
"up": "ncu -u && npm install && npm update && npm audit fix"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/sefinek24/google-tts-api.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"tts",
|
|
18
|
+
"google",
|
|
19
|
+
"google-tts",
|
|
20
|
+
"text-to-speech",
|
|
21
|
+
"google-text-to-speech"
|
|
22
|
+
],
|
|
23
|
+
"author": "zlargon",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/sefinek24/google-tts-api/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/sefinek24/google-tts-api#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.6.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"is-base64": "^1.1.0",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"typescript": "^5.3.2"
|
|
36
|
+
},
|
|
37
|
+
"jest": {
|
|
38
|
+
"testEnvironment": "node",
|
|
39
|
+
"coverageReporters": [
|
|
40
|
+
"lcov",
|
|
41
|
+
"text",
|
|
42
|
+
"html"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
13
|
+
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
+
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
"sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
18
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
+
|
|
44
|
+
/* Module Resolution Options */
|
|
45
|
+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
46
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
47
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
48
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
49
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
50
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
51
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
52
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
53
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
54
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
55
|
+
|
|
56
|
+
/* Source Map Options */
|
|
57
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
58
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
59
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
60
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
61
|
+
|
|
62
|
+
/* Experimental Options */
|
|
63
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
64
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
65
|
+
|
|
66
|
+
/* Advanced Options */
|
|
67
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
68
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
69
|
+
},
|
|
70
|
+
"include": [
|
|
71
|
+
"src"
|
|
72
|
+
]
|
|
73
|
+
}
|