compromise-speech 0.1.1 → 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.
- package/LICENSE +21 -0
- package/README.md +89 -21
- package/builds/compromise-speech.cjs +483 -279
- package/builds/compromise-speech.min.js +1 -1
- package/builds/compromise-speech.mjs +1 -1
- package/package.json +45 -30
- package/src/_version.js +1 -0
- package/src/api.js +5 -5
- package/src/plugin.js +9 -3
- package/src/{compute/soundsLike → sounds-like}/transformations.js +1 -1
- package/src/syllables/index.js +12 -0
- package/src/syllables/split/_lib.js +32 -0
- package/src/syllables/split/find-cuts/00-exceptions.js +81 -0
- package/src/syllables/split/find-cuts/01-vowel-span.js +155 -0
- package/src/syllables/split/find-cuts/02-boundaries.js +86 -0
- package/src/syllables/split/find-cuts/_compound-prefixes.js +22 -0
- package/src/syllables/split/find-cuts/index.js +27 -0
- package/src/syllables/split/index.js +22 -0
- package/types/index.d.cts +9 -0
- package/{index.d.ts → types/index.d.ts} +1 -1
- package/src/compute/index.js +0 -7
- package/src/compute/syllables/index.js +0 -13
- package/src/compute/syllables/postProcess.js +0 -107
- package/src/compute/syllables/syllables.js +0 -90
- /package/src/{compute/soundsLike → sounds-like}/index.js +0 -0
- /package/src/{compute/soundsLike → sounds-like}/metaphone.js +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Spencer Kelly
|
|
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
CHANGED
|
@@ -1,42 +1,86 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
<div>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<div><b>compromise-speech</b></div>
|
|
3
|
+
<div>pronounciation plugin for <a href="https://github.com/spencermountain/compromise/">compromise</a></div>
|
|
4
|
+
<div><code>npm install compromise-speech</code></div>
|
|
5
|
+
<div align="center">
|
|
6
|
+
<sub>
|
|
7
|
+
by
|
|
8
|
+
<a href="https://github.com/spencermountain">Spencer Kelly</a>
|
|
9
|
+
</sub>
|
|
10
|
+
</div>
|
|
11
|
+
<img height="25px" src="https://user-images.githubusercontent.com/399657/68221824-09809d80-ffb8-11e9-9ef0-6ed3574b0ce8.png"/>
|
|
12
|
+
</div>
|
|
13
|
+
<!--2nd row-->
|
|
14
|
+
<div align="center">
|
|
15
|
+
<div>
|
|
16
|
+
<a href="https://npmjs.org/package/compromise-speech">
|
|
8
17
|
<img src="https://img.shields.io/npm/v/compromise-speech.svg?style=flat-square" />
|
|
9
18
|
</a>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<a href="https://unpkg.com/compromise-speech/builds/compromise-speech.min.js">
|
|
13
|
-
<img src="https://badge-size.herokuapp.com/spencermountain/compromise/master/plugins/speech/builds/compromise-speech.min.js" />
|
|
19
|
+
<a href="https://bundlephobia.com/result?p=compromise-speech">
|
|
20
|
+
<img src="https://badgen.net/bundlejs/min/compromise-speech" />
|
|
14
21
|
</a>
|
|
15
|
-
|
|
16
|
-
<div align="center">
|
|
17
|
-
<code>npm install compromise-speech</code>
|
|
18
22
|
</div>
|
|
19
23
|
</div>
|
|
20
|
-
|
|
21
24
|
<!-- spacer -->
|
|
22
|
-
<img height="
|
|
25
|
+
<img height="20px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>
|
|
23
26
|
|
|
24
27
|
### Syllables
|
|
25
|
-
|
|
28
|
+
|
|
29
|
+
Tokenize a word approximately by it's pronounced syllables.
|
|
30
|
+
We use a custom rule-based alortithm for this, to split the words into intuitive, readable syllable chunks.
|
|
31
|
+
|
|
26
32
|
```js
|
|
27
33
|
import plg from 'compromise-speech'
|
|
28
34
|
nlp.extend(plg)
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
const doc = nlp(`Albertville, Saskatchewan`)
|
|
31
37
|
doc.syllables()
|
|
32
|
-
|
|
38
|
+
/*
|
|
39
|
+
[
|
|
40
|
+
[
|
|
41
|
+
'Al',
|
|
42
|
+
'bert',
|
|
43
|
+
'ville,',
|
|
44
|
+
'Sa',
|
|
45
|
+
'skat',
|
|
46
|
+
'che',
|
|
47
|
+
'wan'
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
*/
|
|
33
51
|
```
|
|
34
52
|
|
|
35
|
-
|
|
53
|
+
Results are returned as an array of sentences, split by syllable.
|
|
54
|
+
|
|
55
|
+
If you want to return the individual words, or any other custom splitting:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const doc = nlp(`Calgary Flames`)
|
|
59
|
+
const byTerm = doc.terms().syllables()
|
|
60
|
+
// [ [ 'Cal', 'ga', 'ry' ], [ 'Flames' ] ]
|
|
61
|
+
|
|
62
|
+
const doc = nlp(`it stars Alicia Silverstone and Paul Rudd`)
|
|
63
|
+
const pronounceNames = doc.people().syllables()
|
|
64
|
+
//[
|
|
65
|
+
// [ 'A', 'li', 'cia', 'Sil', 'ver', 'stone' ],
|
|
66
|
+
// [ 'Paul', 'Rudd' ]
|
|
67
|
+
// ]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
you can have it operate on normalized words as well:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const doc = nlp(`BACK to Winnipeg!`)
|
|
74
|
+
doc.syllables({ normalize: true })
|
|
75
|
+
// [ [ 'back', 'to', 'win', 'ni', 'peg' ] ]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
if you'd like to combine syllable information with other properties, you can use `.compute('syllables')`
|
|
79
|
+
|
|
36
80
|
```js
|
|
37
81
|
let doc = nlp('edmonton oilers')
|
|
38
82
|
doc.compute('syllables')
|
|
39
|
-
doc.json()
|
|
83
|
+
const json = doc.json()
|
|
40
84
|
/*[{
|
|
41
85
|
"terms": [
|
|
42
86
|
{
|
|
@@ -52,7 +96,14 @@ doc.json()
|
|
|
52
96
|
*/
|
|
53
97
|
```
|
|
54
98
|
|
|
99
|
+
<!-- spacer -->
|
|
100
|
+
<img height="30px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>
|
|
101
|
+
<div align="center">
|
|
102
|
+
<img height="50px" src="https://user-images.githubusercontent.com/399657/68221814-05ed1680-ffb8-11e9-8b6b-c7528d163871.png"/>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
55
105
|
### SoundsLike
|
|
106
|
+
|
|
56
107
|
Generate an expected pronounciation for the word, as a normalized string.
|
|
57
108
|
We use the [metaphone implementation](https://en.wikipedia.org/wiki/Metaphone), which is a simple rule-based pronounciation system.
|
|
58
109
|
|
|
@@ -66,6 +117,7 @@ doc.soundsLike()
|
|
|
66
117
|
```
|
|
67
118
|
|
|
68
119
|
Alternatively, if you'd like to combine syllable information with other properties, you can use `.compute('syllables')`
|
|
120
|
+
|
|
69
121
|
```js
|
|
70
122
|
let doc = nlp('edmonton oilers')
|
|
71
123
|
doc.compute('soundsLike')
|
|
@@ -85,4 +137,20 @@ doc.json()
|
|
|
85
137
|
*/
|
|
86
138
|
```
|
|
87
139
|
|
|
88
|
-
|
|
140
|
+
<!-- spacer -->
|
|
141
|
+
<img height="20px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>
|
|
142
|
+
|
|
143
|
+
### Note
|
|
144
|
+
|
|
145
|
+
Pronunciation is regional, cultural, and even varies person-to-person. Some efforts have been made to support a wide variety of linguistic interpretations, but this may not be very wide indeed.
|
|
146
|
+
Please refer to more sophisticated libraries if your application requires it, or help us improve.
|
|
147
|
+
|
|
148
|
+
### See also
|
|
149
|
+
|
|
150
|
+
- [Talisman syllable tokenizers](https://yomguithereal.github.io/talisman/tokenizers/syllables) (JavaScript) — returns word chunks using SonoriPy's sonority rules or LegaliPy's onset rules learned from a text corpus. A close comparison for splitting the original spelling.
|
|
151
|
+
- [NLTK SyllableTokenizer](https://www.nltk.org/api/nltk.tokenize.sonority_sequencing.html) (Python) — splits words using the Sonority Sequencing Principle, with an English alphabet hierarchy by default; for example, `justification` becomes `jus / ti / fi / ca / tion`.
|
|
152
|
+
- [words/syllable](https://github.com/words/syllable) (JavaScript) — estimates English syllable counts, returning a number rather than word chunks.
|
|
153
|
+
- [hyphen](https://github.com/ytiurin/hyphen) (JavaScript) — uses Liang's hyphenation algorithm and language-specific patterns to insert line-break opportunities into written words.
|
|
154
|
+
- [Hyphenopoly](https://github.com/mnater/Hyphenopoly) (JavaScript/WebAssembly) — hyphenation for browsers and Node. Its [syllabification notes](https://mnater.github.io/Hyphenopoly/Special-use-cases.html#syllabification) explain why line breaks differ from syllable boundaries and describe a German-specific syllable pattern set.
|
|
155
|
+
|
|
156
|
+
MIT
|