Windows 用Perl脚本播放声音

Windows 用Perl脚本播放声音,windows,perl,audio,portability,gnome,Windows,Perl,Audio,Portability,Gnome,我试图在Perl脚本中添加声音,以提醒用户事务正常(用户在工作时可能不会一直看着屏幕)。我希望尽可能保持便携性,因为脚本在Windows和Linux工作站上运行。 我能 对于Windows。但我不知道如何在Linux(Gnome)上调用通用声音。到目前为止,我已经想出了 system('paplay /usr/share/sounds/gnome/default/alert/sonar.ogg'); 但我不确定我是否能指望这条路可用。 因此,有三个问题: 在Gnome中调用默认声音有更好的方法

我试图在Perl脚本中添加声音,以提醒用户事务正常(用户在工作时可能不会一直看着屏幕)。我希望尽可能保持便携性,因为脚本在Windows和Linux工作站上运行。
我能

对于Windows。但我不知道如何在Linux(Gnome)上调用通用声音。到目前为止,我已经想出了

system('paplay /usr/share/sounds/gnome/default/alert/sonar.ogg');
但我不确定我是否能指望这条路可用。
因此,有三个问题:

  • 在Gnome中调用默认声音有更好的方法吗
  • 这条路是否相当普遍(至少在Debain/Ubuntu风格中是如此)
  • paplay
    播放声音后需要一段时间才能退出,有没有更好的方法调用它
  • 我宁愿远离系统扬声器的哔哔声,这听起来很糟糕(这会被频繁播放),Ubuntu也会将PC扬声器列入黑名单。

    谢谢

    获取
    paplay
    路径(假设存在)的更方便的方法可能是使用。然后可以得到如下路径:

    use File::Which;
    my $paplay_path = which 'paplay';
    
    要异步播放声音,您可以
    fork
    a子流程:

    my $pid = fork;
    if ( !$pid ) { 
        # in the child process
        system $paplay_path, '/usr/share/sounds/gnome/default/alert/sonar.ogg';
    }
    
    # parent proc continues here
    

    还要注意,我使用了
    system
    的多参数形式;这样做可以避免shell并直接运行请求的程序。这避免了危险的bug(而且效率更高)。

    我想使用
    fork
    ,但我不确定这是否会导致重复调用更多问题。我试试看。谢谢另外,我指的是可以播放的声音文件的路径(而不是
    paplay
    本身)。但我认为这是相同的想法,我将一直(-R$path)直到找到一个有效的方法
    fork
    必须显式调用
    CORE::exit()
    POSIX::\u exit()
    否则会发生可怕的事情。
    my $pid = fork;
    if ( !$pid ) { 
        # in the child process
        system $paplay_path, '/usr/share/sounds/gnome/default/alert/sonar.ogg';
    }
    
    # parent proc continues here