Skip to content
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

Apply patch of say.js #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
"version": "2.0.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isWatching": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
"problemMatcher": "$tsc-watch",
"tasks": [
{
"label": "npm",
"type": "shell",
"command": "npm",
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
"isBackground": true,
"problemMatcher": "$tsc-watch",
"group": {
"_id": "build",
"isDefault": false
}
}
]
}
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"theme": "light"
},
"engines": {
"vscode": "^1.5.0"
"vscode": "^1.63.1"
},
"categories": [
"Other"
Expand Down Expand Up @@ -102,27 +102,25 @@
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
},
"devDependencies": {
"@types/node": "^10.12.2",
"@types/vscode": "^1.63.1",
"husky": "^1.1.3",
"lint-staged": "^8.0.4",
"prettier": "^1.14.3",
"typescript": "^3.1.6",
"vscode": "^1.1.18"
"typescript": "^3.1.6"
},
"dependencies": {
"@textlint/ast-node-types": "^4.0.3",
"@textlint/ast-traverse": "^2.0.9",
"@textlint/kernel": "^3.0.0",
"@textlint/textlint-plugin-markdown": "^5.0.1",
"@textlint/textlint-plugin-text": "^4.0.1",
"@types/p-queue": "^3.0.0",
"@types/structured-source": "^3.0.0",
"p-queue": "^3.0.0",
"say": "^0.15.0",
"p-queue": "^6.6.2",
"say": "MatchaChoco010/say.js#make-3rd-party-voice-available",
Copy link
Owner

@azu azu Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to publish it as package.
Git's Branch is not immutable.

Scoped package is useful for fork repository.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will publish this fork repository as scoped package.

"sentence-splitter": "^3.0.11",
"structured-source": "^3.0.2",
"textlint-plugin-review": "^0.3.3",
Expand Down
25 changes: 13 additions & 12 deletions src/SpeechEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { createParser } from "./parser";
import { traverse, VisitorOption } from "@textlint/ast-traverse";
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter";
const StringSource = require("textlint-util-to-string");
import PQueue = require("p-queue");
import PQueue from "p-queue";
import { EventEmitter } from "events";

import StructuredSource = require("structured-source");
const StructuredSource = require("structured-source");
/**
* Line number starts with 1.
* Column number starts with 0.
*/
export type SpeechEnginePosition = { line: number; column: number };
export class SpeechEngine extends EventEmitter {
private txtAST: TxtNode;
private txtAST: TxtNode | { text: string; ast: TxtNode };
private txtNodes: TxtNode[];
private speechIndex: number;
private promiseQueue: PQueue<PQueue.DefaultAddOptions>;
private promiseQueue: PQueue;
public status: "pause" | "play" | "stop" = "stop";
constructor(
private text: string,
Expand All @@ -33,19 +33,15 @@ export class SpeechEngine extends EventEmitter {
return structuredSource.positionToIndex(position);
};
const startIndex = loc ? positionToIndex(loc.start) : null;
const endIndex = loc
? loc.end
? positionToIndex(loc.end)
: Infinity
: null;
const endIndex = loc ? (loc.end ? positionToIndex(loc.end) : Infinity) : null;
const parser = createParser([
{
pluginId: "text",
plugin: require("@textlint/textlint-plugin-text")
plugin: require("@textlint/textlint-plugin-text").default
},
{
pluginId: "markdown",
plugin: require("@textlint/textlint-plugin-markdown")
plugin: require("@textlint/textlint-plugin-markdown").default
},
{
pluginId: "review",
Expand Down Expand Up @@ -94,7 +90,11 @@ export class SpeechEngine extends EventEmitter {
if (!isIncludedNode(node)) {
return;
}
if (node.type === ASTNodeTypes.Paragraph || node.type === ASTNodeTypes.Header || node.type === "TableCell") {
if (
node.type === ASTNodeTypes.Paragraph ||
node.type === ASTNodeTypes.Header ||
node.type === "TableCell"
) {
const parentNode = splitAST(node as TxtParentNode);
parentNode.children.forEach(node => {
if (!isIncludedNode(node)) {
Expand Down Expand Up @@ -135,6 +135,7 @@ export class SpeechEngine extends EventEmitter {
this.speechIndex++;
})
.catch(error => {
console.log("oh");
this.speechIndex++;
});
});
Expand Down
38 changes: 22 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as vscode from "vscode";
import { SpeechEngine, SpeechEnginePosition } from "./SpeechEngine";
import { Disposer } from "bluebird";
const getVoice = (): string => vscode.workspace.getConfiguration("read-aloud-text").get<string>("voice");
const getVoice = (): string => vscode.workspace.getConfiguration("read-aloud-text").get<string>("voice") as string;

const getSpeed = (): number => vscode.workspace.getConfiguration("read-aloud-text").get<number>("speed");
const getSpeed = (): number => vscode.workspace.getConfiguration("read-aloud-text").get<number>("speed") as number;

let highlightDecorator: vscode.TextEditorDecorationType | null = null;
function highlightRange({ startIndex, endIndex }: { startIndex: number; endIndex: number }) {
Expand Down Expand Up @@ -64,18 +63,22 @@ const speech = {
if (fileName !== activeEditor.document.fileName) {
return;
}
disposeFns.push(vscode.workspace.onDidCloseTextDocument((event) => {
const changedFileName = event.fileName;
if (fileName === changedFileName) {
this.stop();
}
}));
disposeFns.push(vscode.workspace.onDidChangeTextDocument((event) => {
const changedFileName = event.document.fileName;
if (fileName === changedFileName) {
this.stop();
}
}));
disposeFns.push(
vscode.workspace.onDidCloseTextDocument(event => {
const changedFileName = event.fileName;
if (fileName === changedFileName) {
this.stop();
}
})
);
disposeFns.push(
vscode.workspace.onDidChangeTextDocument(event => {
const changedFileName = event.document.fileName;
if (fileName === changedFileName) {
this.stop();
}
})
);
highlightRange({
startIndex: currentNode.range[0],
endIndex: currentNode.range[1]
Expand All @@ -90,7 +93,7 @@ const speech = {
if (highlightDecorator) {
highlightDecorator.dispose();
}
disposeFns.forEach((disposable) => {
disposeFns.forEach(disposable => {
disposable.dispose();
});
disposeFns = [];
Expand Down Expand Up @@ -160,3 +163,6 @@ export function activate(context: vscode.ExtensionContext) {
})
);
}

function Hoge() {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. This is debug code. I will remove it.

console.log(Hoge);
Loading