mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-11 08:30:31 +00:00
Use read().done to verify all bytes are written
Substitute using existing defined done of ReadableStreamDefaultReader.read() for value.length < this.channelDataLength && (await this.inputReader.read()).done to verify all input stream bytes are written
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
class AudioStream {
|
||||
constructor({ stdin, recorder = false }) {
|
||||
if (!/^espeak-ng/.test(stdin)) {
|
||||
@@ -197,7 +196,21 @@ class AudioStream {
|
||||
write: async ({ timestamp }) => {
|
||||
const { value, done } = await this.inputReader.read();
|
||||
if (done) {
|
||||
await this.inputReader.closed;
|
||||
console.log({ done });
|
||||
try {
|
||||
await this.disconnect();
|
||||
} catch (err) {
|
||||
console.warn(err.message);
|
||||
}
|
||||
console.log(
|
||||
`readOffset:${this.readOffset}, duration:${this.duration}, ac.currentTime:${this.ac.currentTime}`,
|
||||
`generator.readyState:${this.generator.readyState}, audioWriter.desiredSize:${this.audioWriter.desiredSize}`
|
||||
);
|
||||
return await Promise.all([
|
||||
new Promise((resolve) => (this.stream.oninactive = resolve)),
|
||||
new Promise((resolve) => (this.ac.onstatechange = resolve)),
|
||||
]);
|
||||
}
|
||||
const uint16 = new Uint16Array(value.buffer);
|
||||
// https://stackoverflow.com/a/35248852
|
||||
@@ -228,24 +241,6 @@ class AudioStream {
|
||||
this.recorder.start();
|
||||
}
|
||||
await this.audioWriter.write(frame);
|
||||
if (
|
||||
value.length < this.channelDataLength &&
|
||||
(await this.inputReader.read()).done
|
||||
) {
|
||||
try {
|
||||
await this.disconnect();
|
||||
} catch (err) {
|
||||
console.warn(err.message);
|
||||
}
|
||||
console.log(
|
||||
`readOffset:${this.readOffset}, duration:${this.duration}, ac.currentTime:${this.ac.currentTime}`,
|
||||
`generator.readyState:${this.generator.readyState}, audioWriter.desiredSize:${this.audioWriter.desiredSize}`
|
||||
);
|
||||
return await Promise.all([
|
||||
new Promise((resolve) => (this.stream.oninactive = resolve)),
|
||||
new Promise((resolve) => (this.ac.onstatechange = resolve)),
|
||||
]);
|
||||
}
|
||||
},
|
||||
abort(e) {
|
||||
console.error(e.message);
|
||||
|
||||
Reference in New Issue
Block a user