-
Notifications
You must be signed in to change notification settings - Fork 4
not wasm stuff #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
7coil
wants to merge
3
commits into
dectalk-develop
Choose a base branch
from
wasmstuff
base: dectalk-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
not wasm stuff #26
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,6 @@ out/ | |
| toolchain | ||
| say | ||
| /wip | ||
|
|
||
| # Nintendo DS | ||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "configurations": [ | ||
| { | ||
| "name": "Mac", | ||
| "includePath": [ | ||
| "${workspaceFolder}/**" | ||
| ], | ||
| "defines": [], | ||
| "compilerPath": "/usr/bin/clang", | ||
| "cStandard": "c17", | ||
| "cppStandard": "c++14", | ||
| "intelliSenseMode": "macos-clang-arm64" | ||
| } | ||
| ], | ||
| "version": 4 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [{ | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "name": "DECtalk for NodeJS", | ||
| "preLaunchTask": "npm: build:dev - node", | ||
| "program": "/usr/bin/env", | ||
| "args": [ | ||
| "node", | ||
| "${workspaceFolder}/node/src/index.js" | ||
| ] | ||
| }] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
| build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "target_name": "dectalk", | ||
| "cflags!": [ "-fno-exceptions" ], | ||
| "cflags_cc!": [ "-fno-exceptions" ], | ||
| "sources": [ | ||
| "src/dectalk.cc", | ||
| "<!@(node -p \"require('fs').readdirSync('../src').map(f=>'../src/'+f).join(' ')\")" | ||
| ], | ||
| "include_dirs": [ | ||
| "../include", | ||
| "<!@(node -p \"require('node-addon-api').include\")" | ||
| ], | ||
| 'defines': [ | ||
| 'NAPI_DISABLE_CPP_EXCEPTIONS', | ||
| 'NO_FILESYSTEM', | ||
| '_REENTRANT', | ||
| 'NOMME', | ||
| 'LTSSIM', | ||
| 'TTSSIM', | ||
| 'ANSI', | ||
| 'BLD_DECTALK_DLL', | ||
| 'ENGLISH', | ||
| 'ENGLISH_US', | ||
| 'ACCESS32', | ||
| 'TYPING_MODE', | ||
| 'ACNA', | ||
| 'DISABLE_AUDIO', | ||
| 'SINGLE_THREADED', | ||
| '__unix__' | ||
| ], | ||
| } | ||
| ] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "hello_world", | ||
| "version": "0.0.0", | ||
| "description": "Node.js Addons Example #1", | ||
| "main": "src/index.js", | ||
| "private": true, | ||
| "dependencies": { | ||
| "bindings": "~1.5.0", | ||
| "node-addon-api": "^8.1.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "node-gyp build", | ||
| "build:dev": "node-gyp build --debug" | ||
| }, | ||
| "gypfile": true, | ||
| "devDependencies": { | ||
| "node-api-headers": "^1.8.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #include <napi.h> | ||
|
|
||
| extern "C" { | ||
| #include "epsonapi.h" | ||
| } | ||
|
|
||
| Napi::FunctionReference callback; | ||
| bool callbackWasSet = false; | ||
|
|
||
| short* audio_callback(short *data, long length, int phoneme) { | ||
| Napi::Env env = callback.Env(); | ||
|
|
||
| Napi::Buffer<short> array = Napi::Buffer<short>::New(env, data, length); | ||
|
|
||
| callback.Call({ array }); | ||
| } | ||
|
|
||
| Napi::Value setCallback(const Napi::CallbackInfo& info) { | ||
| Napi::Env env = info.Env(); | ||
|
|
||
| callback = Napi::Persistent(info[0].As<Napi::Function>()); | ||
| callbackWasSet = true; | ||
|
|
||
| return Napi::String::New(env, "Done"); | ||
| } | ||
|
|
||
| Napi::Value say(const Napi::CallbackInfo& info) { | ||
| Napi::Env env = info.Env(); | ||
|
|
||
| Napi::String text = info[0].As<Napi::String>(); | ||
| Napi::Number format = info[1].As<Napi::Number>(); | ||
|
|
||
| const std::string cppstr = text.ToString().Utf8Value(); | ||
| const char* input = cppstr.c_str(); | ||
| const int fmt = format.Int32Value(); | ||
|
|
||
| int result = TextToSpeechStart((char*) input, NULL, fmt); | ||
|
|
||
| if (result == 0) TextToSpeechSync(); | ||
|
|
||
| return Napi::Number::New(env, result); | ||
| } | ||
|
|
||
| Napi::Object Init(Napi::Env env, Napi::Object exports) { | ||
| exports.Set(Napi::String::New(env, "setCallback"), | ||
| Napi::Function::New(env, setCallback)); | ||
|
|
||
| exports.Set(Napi::String::New(env, "say"), | ||
| Napi::Function::New(env, say)); | ||
|
|
||
| TextToSpeechInit(audio_callback, NULL); | ||
|
|
||
| return exports; | ||
| } | ||
|
|
||
| // Register and initialize native add-on | ||
| NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| interface ILibDectalk { | ||
| setCallback: (callback: (buffer: Buffer) => void) => void; | ||
| say: (text: string, mode: 0 | 1) => number; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import bindings from "bindings"; | ||
| import fs from "node:fs" | ||
|
|
||
| /** @type {ILibDectalk} */ | ||
| const libdectalk = bindings("dectalk"); | ||
|
|
||
| const toBytes = (number) => { | ||
| return [0xff & number, | ||
| 0xff & (number >> 8), | ||
| 0xff & (number >> 16), | ||
| 0xff & (number >> 24)] | ||
| } | ||
|
|
||
| /** @type {(text: string) => Promise<Buffer>} */ | ||
| const say = (text) => { | ||
| const format = 1; | ||
| const audioBuffer = []; | ||
| let dataLength = 0; | ||
|
|
||
| /** @type {(chunkData: Buffer) => void} */ | ||
| const callback = (chunkData) => { | ||
| // copy the buffer immediately before its destroyed | ||
| audioBuffer.push(Buffer.from(chunkData)); | ||
| dataLength += chunkData.byteLength; | ||
| } | ||
|
|
||
| libdectalk.setCallback(callback) | ||
| libdectalk.say(text, format); | ||
|
|
||
| const sampleRate = format ? 11025 : 8000 | ||
| const bufferLength = 44 + dataLength; | ||
|
|
||
| // Generate a WAV header | ||
| const header = Buffer.from([ | ||
| 0x52, 0x49, 0x46, 0x46, // RIFF | ||
| ...toBytes(bufferLength), // WAV size | ||
| 0x57, 0x41, 0x56, 0x45, // WAVE | ||
| 0x66, 0x6d, 0x74, 0x20, // fmt | ||
| 0x10, 0x00, 0x00, 0x00, // fmt chunk size | ||
| 0x01, 0x00, 0x01, 0x00, // Audio format 1=PCM & Number of channels 1=Mono | ||
| ...toBytes(sampleRate), // Sampling Frequency in Hz | ||
| ...toBytes(sampleRate * 2), // bytes per second | ||
| 0x02, 0x00, 0x10, 0x00, // 2=16-bit mono & Number of bits per sample | ||
| 0x64, 0x61, 0x74, 0x61, // data | ||
| ...toBytes(dataLength) // data size | ||
| ]) | ||
|
|
||
| return Buffer.concat([header, ...audioBuffer]) | ||
| } | ||
|
|
||
| const buffer = say("This is a message from Node J S"); | ||
| fs.writeFileSync("first.wav", buffer); | ||
|
|
||
| const buffer2 = say("This is a second message from Node J S"); | ||
| fs.writeFileSync("second.wav", buffer2); | ||
| console.log("end of programme"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops still havent done anything with this lol