有没有办法让 Ubuntu 读出通知?

Meo*_*eow 9 notify-osd text-to-speech

Ubuntu 有一个非常酷的通知系统。有没有办法让 Ubuntu 在通知出现时读出通知?

或者是否可以将通知中的文本链接到espeak

Sau*_*mar 17

这个问题真的很有趣,所以作为答案。

dbus-monitor执行时等待信号,到达时捕获并提供有关它的适当信息。同样可以执行它来获取有关Notifications的信息。执行时:

dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "member=Notify\|string"
Run Code Online (Sandbox Code Playgroud)

它将等待通知,当任何通知到达时,它会提供通知的信息。

例如,当声音增加/减少或任何歌曲曲目更改或任何其他时,它会给出消息。我notify-send 在任何其他终端上使用命令手动创建桌面通知:

notify-send "Hello How are you?"
Run Code Online (Sandbox Code Playgroud)

然后dbus-monitor执行命令的第一个终端将给出如下消息:

saurav@saurav-P4I45Gx-PE:~$ dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "member=Notify\|string"
   string ":1.473"
method call sender=:1.474 -> dest=:1.475 serial=7    path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications;  member=Notify
   string "notify-send"
   string ""
   string "Hello How Are You?"
   string ""
         string "urgency"
Run Code Online (Sandbox Code Playgroud)

现在上面的输出可以很容易地传递espeak给阅读消息。例如,

dbus-monitor用以下命令替换上面的命令将读取通知消息:

检查,它是如何工作的:

  • 在终端中执行此命令并保持运行:

    dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "string" | grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | grep --line-buffered -v '^\s*$' | xargs -I '{}' espeak {}
    
    Run Code Online (Sandbox Code Playgroud)

    我知道它变得很长,但没有其他方法可以使它变小,因为实际通知的过滤使它变得冗长。

  • 然后以我上面描述的方式notify-send或任何其他方式运行桌面通知。我正在使用notify-send. 所以在其他终端执行以下命令:

    notify-send "Hello! I am Saurav Kumar."
    
    Run Code Online (Sandbox Code Playgroud)

    只要您执行命令,它就会说出(阅读)通知。

虽然它吃了我 4-5 个小时,但我现在很高兴让它工作。

您还可以创建自己的命令,saynoti并在每次需要阅读通知时执行它。您可以按照以下步骤操作:

我想说谢谢你提出这个问题。因为这个问题,我学到了很多东西。:)

如果您遇到任何问题或需要任何进一步的更改/修改,请回复。我相信你会很高兴得到最终的工作版本。

  • 伙计,你太棒了,不能再问别的了;我把它放在我的启动列表中,它完美地工作 merci beaucoup (2认同)