Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

语音对话中,勾选了自动发送,但实际上还是要手动点击发送按钮 #4378

Closed
2 of 7 tasks
361so opened this issue Mar 28, 2025 · 6 comments
Closed
2 of 7 tasks
Labels
bug Something isn't working

Comments

@361so
Copy link

361so commented Mar 28, 2025

例行检查

  • 我已确认目前没有类似 issue
  • 我已完整查看过项目 README,以及项目文档
  • 我使用了自己的 key,并确认我的 key 是可正常使用的
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

你的版本

  • 公有云版本
  • 私有部署版本, 具体版本号:

问题描述, 日志截图,配置文件等

复现步骤

预期结果

相关截图

Image

@361so 361so added the bug Something isn't working label Mar 28, 2025
@huliangbing
Copy link

同样的问题

@361so
Copy link
Author

361so commented Mar 31, 2025

Image
在useSpeech.ts中找到相关代码,语音输入60s后自动发送,这不是不是不太合理?不能主动判断语音是否输入完了吗?是不是可以通过分析音频音量来判断用户是否停止说话?

@361so
Copy link
Author

361so commented Mar 31, 2025

目前让AI简单增加了个方法
`// ... existing code ...

export const useSpeech = (props?: OutLinkChatAuthProps & { appId?: string }) => {
// ... existing state ...
const silenceCounter = useRef(0); // 新增:静音计数器
const analyserRef = useRef(); // 新增:音频分析器

const checkSilence = useCallback(() => {
if (!analyserRef.current) return;

const bufferLength = analyserRef.current.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);
analyserRef.current.getByteFrequencyData(dataArray);

// 计算平均音量
const volume = dataArray.reduce((sum, value) => sum + value, 0) / bufferLength;

if (volume < 20) { // 音量阈值,可根据实际情况调整
  silenceCounter.current++;
  if (silenceCounter.current >= 3) { // 连续3秒静音则停止录音
    stopSpeak();
  }
} else {
  silenceCounter.current = 0; // 有声音则重置计数器
}

}, []);

const startSpeak = async (onFinish: (text: string) => void) => {
if (!navigator?.mediaDevices?.getUserMedia) {
return toast({
status: 'warning',
title: t('common:common.speech.not support')
});
}
try {
silenceCounter.current = 0; // 重置静音计数器
cancelWhisperSignal.current = false;

  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  setMediaStream(stream);

  // 设置音频分析器
  const audioContext = new AudioContext();
  const analyser = audioContext.createAnalyser();
  analyser.fftSize = 256;
  const source = audioContext.createMediaStreamSource(stream);
  source.connect(analyser);
  analyserRef.current = analyser;

  mediaRecorder.current = new MediaRecorder(stream);
  // ... existing code ...

  // 添加静音检测定时器
  intervalRef.current = setInterval(() => {
    const currentTimestamp = Date.now();
    const duration = (currentTimestamp - startTimestamp.current) / 1000;
    setAudioSecond(duration);
    checkSilence(); // 每秒检测一次静音
  }, 1000);

  // ... existing code ...
} catch (error) {
  // ... existing error handling ...
}

};

// ... rest of the code ...
};`

@c121914yu
Copy link
Collaborator

Image
在useSpeech.ts中找到相关代码,语音输入60s后自动发送,这不是不是不太合理?不能主动判断语音是否输入完了吗?是不是可以通过分析音频音量来判断用户是否停止说话?

这是避免长时间说话

@c121914yu
Copy link
Collaborator

c121914yu commented Apr 7, 2025

试了试没啥问题,停止说话后就发送了。

@goactiongo
Copy link

goactiongo commented Apr 7, 2025 via email

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants