Skip to content

Commit

Permalink
Merge tag '0.3.0'
Browse files Browse the repository at this point in the history
Feature release 0.3.0

Features:
- New method `SamJs.wav(text: string, phonetic?: boolean): Uint8Array;`
which
  renders a wave buffer.
  See #46, #47 (thanks to @seofernando25)

Fixes:
- Typo `dipthong` has been corrected to `diphthong` all over the code
base.
This includes the flag `FLAG_DIPTHONG` which is now named
`FLAG_DIPHTHONG`.
  Fixes #19
- Fix comments to clearify that the '*' is not a wildcard but a marker
that the
  second char in a phoneme is to be ignored.
  Fixes # 21

Additionally minor changes like adding download in demo html file.
  • Loading branch information
discordier committed Jun 11, 2024
2 parents f49fa37 + 917016b commit 5eb6e56
Show file tree
Hide file tree
Showing 39 changed files with 1,945 additions and 1,749 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ on:
push:
branches:
- master
- release/*

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16' ]
node: [ '18', '20', '22' ]
install: [ '', '--frozen-lockfile' ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: yarn install ${{ matrix.install }}
- run: yarn test

22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,47 @@ GLOBAL_DEPS=Makefile $(wildcard src/**.es6) build/build.js build/config.js node_
PROJECT_DIR=$(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GH_PAGES_PATH=$(PROJECT_DIR)/gh-pages

.PHONY: test build

.PHONY: all
all: test build

.PHONY: test
test: $(GLOBAL_DEPS)
yarn test

.PHONY: build
build: $(GLOBAL_DEPS)
yarn build

node_modules:
yarn install --frozen-lockfile

.PHONY: release-docs
release-docs: gh-pages build $(PROJECT_DIR)/dist/samjs.min.js $(PROJECT_DIR)/dist/guessnum.min.js
cp $(PROJECT_DIR)/dist/samjs.min.js \
$(PROJECT_DIR)/dist/guessnum.min.js \
$(GH_PAGES_PATH)/dist
git -C $(GH_PAGES_PATH) add .
git -C $(GH_PAGES_PATH) commit -m "update release"

.PHONY: gh-pages
gh-pages: $(GLOBAL_DEPS)
ifeq ($(wildcard $(GH_PAGES_PATH)/),)
git clone -b gh-pages $(shell git remote get-url --push origin) $(GH_PAGES_PATH)
else
(cd $(GH_PAGES_PATH) && git pull)
endif

UID="$(shell id -u)"
GID="$(shell id -g)"
PROJECT_DIR=$(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
.PHONY: build-docker-image
build-docker-image:
docker build build/docker -t sam-build:latest

.PHONY: build-with-docker
build-with-docker: build-docker-image
docker run --rm -it --user $(UID):$(GID) -v$(PROJECT_DIR):/project sam-build:latest make all

.PHONY: node-docker
node-shell: build-docker-image
docker run --rm -it --user $(UID):$(GID) -v$(PROJECT_DIR):/project sam-build:latest /bin/sh
8 changes: 8 additions & 0 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dockerfile to build the image used to build the library.
FROM node:22-alpine

RUN apk --no-cache add make chromium

ENV CHROME_BIN=/usr/bin/chromium

WORKDIR /project
32 changes: 16 additions & 16 deletions dist/guessnum.common.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* This is SamJs.js v0.2.0
* This is SamJs.js v0.3.0
*
* A Javascript port of "SAM Software Automatic Mouth".
*
* (c) 2017-2022 Christian Schiffler
* (c) 2017-2024 Christian Schiffler
*
* @link(https://github.com/discordier/sam)
*
Expand All @@ -24,7 +24,7 @@ let matchesBitmask = (bits, mask) => {
/**
*
* @param {AudioContext} context
* @param audiobuffer
* @param {Float32Array} audiobuffer
*
* @return {Promise}
*/
Expand Down Expand Up @@ -215,7 +215,7 @@ let PhonemeNameTable = (' *' + // 00
* '**', 'KX', '**', '**', 'UM', 'UN'
* 0x0020 FLAG_DIP_YX but looks like front vowels
* 'IY', 'IH', 'EH', 'AE', 'AA', 'AH', 'AX', 'IX', 'EY', 'AY', 'OY'
* 0x0010 FLAG_DIPTHONG
* 0x0010 FLAG_DIPHTHONG
* 'EY', 'AY', 'OY', 'AW', 'OW', 'UW'
* 0x0008
* 'M*', 'N*', 'NX', 'DX', 'Q*', 'CH', 'J*', 'B*', '**', '**', 'D*',
Expand Down Expand Up @@ -517,7 +517,7 @@ SPECIAL
*/

/**
* Match both characters but not with wildcards.
* Match two character phoneme.
*
* @param {string} sign1
* @param {string} sign2
Expand All @@ -531,14 +531,14 @@ let full_match = (sign1, sign2) => {
return index !== -1 ? index : false;
};
/**
* Match character with wildcard.
* Match single character phoneme.
*
* @param {string} sign1
* @return {boolean|Number}
*/


let wild_match = sign1 => {
let single_match = sign1 => {
let index = PhonemeNameTable.findIndex(value => {
return value === sign1 + '*';
});
Expand All @@ -561,11 +561,11 @@ let wild_match = sign1 => {
*
* Repeat until the end is reached:
* 1. First, a search is made for a 2 character match for phonemes that do not
* end with the '*' (wildcard) character. On a match, the index of the phoneme
* end with the '*' (single char mark) character. On a match, the index of the phoneme
* is added to the result and the buffer position is advanced 2 bytes.
*
* 2. If this fails, a search is made for a 1 character match against all
* phoneme names ending with a '*' (wildcard). If this succeeds, the
* phoneme names ending with a '*' (single char mark). If this succeeds, the
* phoneme is added to result and the buffer position is advanced
* 1 byte.
*
Expand Down Expand Up @@ -611,14 +611,14 @@ let Parser1 = (input, addPhoneme, addStress) => {
let match;

if ((match = full_match(sign1, sign2)) !== false) {
// Matched both characters (no wildcards)
// Matched both characters (no single char mark)
srcPos++; // Skip the second character of the input as we've matched it

addPhoneme(match);
continue;
}

if ((match = wild_match(sign1)) !== false) {
if ((match = single_match(sign1)) !== false) {
// Matched just the first character (with second character matching '*'
addPhoneme(match);
continue;
Expand Down Expand Up @@ -671,12 +671,12 @@ let FLAG_PUNCT = 0x0100;
let FLAG_VOWEL = 0x0080;
let FLAG_CONSONANT = 0x0040;
/**
* dipthong ending with YX
* diphthong ending with YX
*
*/

let FLAG_DIP_YX = 0x0020;
let FLAG_DIPTHONG = 0x0010;
let FLAG_DIPHTHONG = 0x0010;
/** unknown:
* 'M*', 'N*', 'NX', 'DX', 'Q*', 'CH', 'J*', 'B*', '**', '**', 'D*',
* '**', '**', 'G*', '**', '**', 'GX', '**', '**', 'P*', '**', '**',
Expand Down Expand Up @@ -797,7 +797,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
continue;
}

if (phonemeHasFlag(phoneme, FLAG_DIPTHONG)) {
if (phonemeHasFlag(phoneme, FLAG_DIPHTHONG)) {
// <DIPHTHONG ENDING WITH WX> -> <DIPHTHONG ENDING WITH WX> WX
// <DIPHTHONG NOT ENDING WITH WX> -> <DIPHTHONG NOT ENDING WITH WX> YX
// Example: OIL, COW
Expand Down Expand Up @@ -933,7 +933,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
if (!phonemeHasFlag(phoneme, FLAG_DIP_YX) && phoneme !== null) {
// replace G with GX and continue processing next phoneme
{
console.log("".concat(pos, " RULE: G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>"));
console.log("".concat(pos, " RULE: G <VOWEL OR DIPHTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPHTHONG NOT ENDING WITH IY>"));
}

setPhoneme(pos, 63); // 'GX'
Expand All @@ -951,7 +951,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
if (!phonemeHasFlag(Y, FLAG_DIP_YX) || Y === null) {
// VOWELS AND DIPHTHONGS ENDING WITH IY SOUND flag set?
{
console.log("".concat(pos, " K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>"));
console.log("".concat(pos, " K <VOWEL OR DIPHTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPHTHONG NOT ENDING WITH IY>"));
}

setPhoneme(pos, 75);
Expand Down
4 changes: 2 additions & 2 deletions dist/guessnum.common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/guessnum.common.min.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions dist/guessnum.esm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* This is SamJs.js v0.2.0
* This is SamJs.js v0.3.0
*
* A Javascript port of "SAM Software Automatic Mouth".
*
* (c) 2017-2022 Christian Schiffler
* (c) 2017-2024 Christian Schiffler
*
* @link(https://github.com/discordier/sam)
*
Expand All @@ -22,7 +22,7 @@ let matchesBitmask = (bits, mask) => {
/**
*
* @param {AudioContext} context
* @param audiobuffer
* @param {Float32Array} audiobuffer
*
* @return {Promise}
*/
Expand Down Expand Up @@ -213,7 +213,7 @@ let PhonemeNameTable = (' *' + // 00
* '**', 'KX', '**', '**', 'UM', 'UN'
* 0x0020 FLAG_DIP_YX but looks like front vowels
* 'IY', 'IH', 'EH', 'AE', 'AA', 'AH', 'AX', 'IX', 'EY', 'AY', 'OY'
* 0x0010 FLAG_DIPTHONG
* 0x0010 FLAG_DIPHTHONG
* 'EY', 'AY', 'OY', 'AW', 'OW', 'UW'
* 0x0008
* 'M*', 'N*', 'NX', 'DX', 'Q*', 'CH', 'J*', 'B*', '**', '**', 'D*',
Expand Down Expand Up @@ -515,7 +515,7 @@ SPECIAL
*/

/**
* Match both characters but not with wildcards.
* Match two character phoneme.
*
* @param {string} sign1
* @param {string} sign2
Expand All @@ -529,14 +529,14 @@ let full_match = (sign1, sign2) => {
return index !== -1 ? index : false;
};
/**
* Match character with wildcard.
* Match single character phoneme.
*
* @param {string} sign1
* @return {boolean|Number}
*/


let wild_match = sign1 => {
let single_match = sign1 => {
let index = PhonemeNameTable.findIndex(value => {
return value === sign1 + '*';
});
Expand All @@ -559,11 +559,11 @@ let wild_match = sign1 => {
*
* Repeat until the end is reached:
* 1. First, a search is made for a 2 character match for phonemes that do not
* end with the '*' (wildcard) character. On a match, the index of the phoneme
* end with the '*' (single char mark) character. On a match, the index of the phoneme
* is added to the result and the buffer position is advanced 2 bytes.
*
* 2. If this fails, a search is made for a 1 character match against all
* phoneme names ending with a '*' (wildcard). If this succeeds, the
* phoneme names ending with a '*' (single char mark). If this succeeds, the
* phoneme is added to result and the buffer position is advanced
* 1 byte.
*
Expand Down Expand Up @@ -609,14 +609,14 @@ let Parser1 = (input, addPhoneme, addStress) => {
let match;

if ((match = full_match(sign1, sign2)) !== false) {
// Matched both characters (no wildcards)
// Matched both characters (no single char mark)
srcPos++; // Skip the second character of the input as we've matched it

addPhoneme(match);
continue;
}

if ((match = wild_match(sign1)) !== false) {
if ((match = single_match(sign1)) !== false) {
// Matched just the first character (with second character matching '*'
addPhoneme(match);
continue;
Expand Down Expand Up @@ -669,12 +669,12 @@ let FLAG_PUNCT = 0x0100;
let FLAG_VOWEL = 0x0080;
let FLAG_CONSONANT = 0x0040;
/**
* dipthong ending with YX
* diphthong ending with YX
*
*/

let FLAG_DIP_YX = 0x0020;
let FLAG_DIPTHONG = 0x0010;
let FLAG_DIPHTHONG = 0x0010;
/** unknown:
* 'M*', 'N*', 'NX', 'DX', 'Q*', 'CH', 'J*', 'B*', '**', '**', 'D*',
* '**', '**', 'G*', '**', '**', 'GX', '**', '**', 'P*', '**', '**',
Expand Down Expand Up @@ -795,7 +795,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
continue;
}

if (phonemeHasFlag(phoneme, FLAG_DIPTHONG)) {
if (phonemeHasFlag(phoneme, FLAG_DIPHTHONG)) {
// <DIPHTHONG ENDING WITH WX> -> <DIPHTHONG ENDING WITH WX> WX
// <DIPHTHONG NOT ENDING WITH WX> -> <DIPHTHONG NOT ENDING WITH WX> YX
// Example: OIL, COW
Expand Down Expand Up @@ -931,7 +931,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
if (!phonemeHasFlag(phoneme, FLAG_DIP_YX) && phoneme !== null) {
// replace G with GX and continue processing next phoneme
{
console.log("".concat(pos, " RULE: G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>"));
console.log("".concat(pos, " RULE: G <VOWEL OR DIPHTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPHTHONG NOT ENDING WITH IY>"));
}

setPhoneme(pos, 63); // 'GX'
Expand All @@ -949,7 +949,7 @@ let Parser2 = (insertPhoneme, setPhoneme, getPhoneme, getStress) => {
if (!phonemeHasFlag(Y, FLAG_DIP_YX) || Y === null) {
// VOWELS AND DIPHTHONGS ENDING WITH IY SOUND flag set?
{
console.log("".concat(pos, " K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>"));
console.log("".concat(pos, " K <VOWEL OR DIPHTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPHTHONG NOT ENDING WITH IY>"));
}

setPhoneme(pos, 75);
Expand Down
4 changes: 2 additions & 2 deletions dist/guessnum.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/guessnum.esm.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 5eb6e56

Please sign in to comment.