按键时发出低延迟声音

发布于 2025-01-08 15:11:19 字数 348 浏览 2 评论 0原文

我正在尝试为我的儿子编写一个应用程序(我是第一次使用 GUI),他患有自闭症。上半部分有一个视频播放器,下半部分有一个文本输入区域。当输入字母时,会产生模仿视频中单词的声音。

该网站上还有其他关于使用 gstreamer 作为系统调用在按键时播放声音的帖子。我也尝试过 libcanberra 但两者似乎在声音之间都有明显的延迟。我可以用 python 或 C 编写应用程序,但可能至少会用 C 编写其中的一部分。

我还想提一下,视频部分是由 gstreamer 播放的。我尝试创建两个 gstreamer 实例,以避免昂贵的系统调用,但音频实例在调用时似乎会杀死该应用程序。

如果有人有任何关于创建更快响应声音的提示,我将非常感激。

I am trying to write an application(I'm a gui first timer) for my son, he has autism. There is a video player in the top half and a text entry area in the bottom. When letters are typed sounds are produced to mimic the words in the video.

There have been other posts on this site in regard to playing sounds on key presses, using gstreamer as a system call. I have also tried libcanberra but both seem to have significant delays between sounds. I can write the app in python or C but will likely do at least some of it in C.

I also want to mention that the video portion is being played by gstreamer. I tried to create two instances of gstreamer, to avoid expensive system calls but the audio instance seemed to kill the app when called.

If anyone has any tips on creating faster responding sounds I would really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2025-01-15 15:11:19

您可以将原始音频样本直接上传到 PulseAudio,这样就不会使用来自 Canberra 的以下函数进行解码和(或许可以节省)额外的开关:

http://developer.gnome.org/libcanberra/unstable/libcanberra-canberra.html#ca-context-cache

下一个 ca_context_play() 将使用它。

然而,在这种情况下(同时视频播放)您会遇到的最大问题是,音频设备可能配置了 PulseAudio 的较大延迟(正常播放时延迟高达 1/2 秒或更长)。向 libcanberra 提交错误以支持 LOW_LATENCY 标志可能是合理的,因为它目前不会尝试最小化声音事件的延迟。如果有的话那就太好了。

GStreamerPulsesink 也可能获得低延迟(它有一些属性),但我担心它不会像 libcanberra 那样轻量级,并且您将无法缓存示例。理想情况下,GStreamer 还可以学习缓存样本,或预填充 PulseAudio...

You can upload a raw audio sample directly to PulseAudio so there will be no decoding and (perhaps save) extra switches by using the following function from Canberra:

http://developer.gnome.org/libcanberra/unstable/libcanberra-canberra.html#ca-context-cache

The next ca_context_play() will use it.

However, the biggest problem you'll encounter with this scenario (with simultaneous video playback) is that the audio device might be configured with large latency with PulseAudio (up to 1/2s or more for normal playback). It may be reasonable to file a bug to libcanberra to support a LOW_LATENCY flag, as it currently doesn't attempt to minimize delay for sound events afaik. That would be great to have.

GStreamer pulsesink could probably get low latency too (it has some properties for that), but I am afraid it won't be as lightweight as libcanberra, and you won't be able to cache a sample for instance. Ideally, GStreamer could also learn to cache samples, or pre-fill PulseAudio...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文