|
|
@@ -114,6 +114,26 @@ export default class NlsAsr extends BaseEvent {
|
|
|
`[nls] 开始采集:AudioContext=${this.audioContext.state} 采样率=${sampleRate}Hz ` +
|
|
|
`processor 缓冲=${this.processor.bufferSize}`
|
|
|
);
|
|
|
+ // 音轨自己的状态 —— 分辨「系统/硬件把麦克风静音了」与「接线有问题」的关键证据:
|
|
|
+ // muted=true 表示轨道被静音(系统静音键、隐私开关、别的程序独占…),
|
|
|
+ // 这时 getUserMedia 照样成功、回调照样触发,但采样全是 0。
|
|
|
+ const track = this.stream.getAudioTracks?.()[0];
|
|
|
+ if (track) {
|
|
|
+ const settings = typeof track.getSettings === "function" ? track.getSettings() : {};
|
|
|
+ console.log(
|
|
|
+ `[nls] 音轨:label=${JSON.stringify(track.label)} muted=${track.muted} enabled=${track.enabled} ` +
|
|
|
+ `state=${track.readyState} deviceId=${String(settings.deviceId || "").slice(0, 8)}… ` +
|
|
|
+ `声道=${settings.channelCount ?? "?"}`
|
|
|
+ );
|
|
|
+ const reportTrackState = (tag: string) => {
|
|
|
+ console.log(`[nls] ${tag}音轨状态:muted=${track.muted} enabled=${track.enabled} state=${track.readyState}`);
|
|
|
+ };
|
|
|
+ window.setTimeout(() => reportTrackState("1.5s 后"), 1500);
|
|
|
+ track.addEventListener?.("mute", () => reportTrackState("被静音时(mute 事件)"));
|
|
|
+ track.addEventListener?.("unmute", () => reportTrackState("解除静音时(unmute 事件)"));
|
|
|
+ } else {
|
|
|
+ console.warn("[nls] ⚠️ 流里没有音轨(getUserMedia 拿到的不是音频流?)");
|
|
|
+ }
|
|
|
this.processor.onaudioprocess = (event: AudioProcessingEvent) => {
|
|
|
if (!this.processing || !this.stream || !this.stream.active) return;
|
|
|
const channel = event.inputBuffer.getChannelData(0);
|