在轨道上播放声音 [英] Playing sound in rails

查看:75
本文介绍了在轨道上播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用coffeescript播放wav文件
我正在使用下面的这段代码来播放声音文件

I'm currently using coffeescript to play wav file
I'm using this code below to play sound file

* *我的Coffeescript

audio = new Audio('error.wav');
audio.play();

我将error.wav放在/app/assets/audio/error.wav

I put error.wav in /app/assets/audio/error.wav

导轨产生错误

在2014-01-28 11:08:04 +0700开始为127.0.0.1获取GET"/touchtypings/error.wav" 由TouchtypingsController#show

Started GET "/touchtypings/error.wav" for 127.0.0.1 at 2014-01-28 11:08:04 +0700 Processing by TouchtypingsController#show

我的理解是,它在运行脚本轨道时试图将error.wav解释为控制器中的路由和进程

my understanding when it run the script rails is trying to interprett error.wav as route and process in controller

我只想在用户键入错误时播放wav文件.
谢谢你的帮助

I just want to play the wav file when user has typed error.
thank you for help

推荐答案

您需要提供音频文件的绝对路径,而不是相对路径.相对路径生成GET /touchtypings/error.wav,这就是为什么路由器会选择它的原因.

You'll need to give an absolute path to the audio file rather than a relative one. The relative path is resulting in GET /touchtypings/error.wav, which is why it's being picked up by the router.

赞:

audio = new Audio('/error.wav'); // note the leading forward slash

根据您的应用程序配置,所需的路径可能是/assets/error.wav而不是/error.wav

And depending on your app config, the path you want is probably going to be /assets/error.wav rather than /error.wav

这篇关于在轨道上播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆