简体   繁体   中英

Play MP3 in browser

I'm trying to allow a user on my site to click a button and via an ajax call load an mp3 file that is created on the server to their browser and then begin playing that file. The file cannot be publicly accessible sense it contains user account specific information. So, I've created the server side code that creates the mp3 but I do not know how to stream the file to the browser from my controller. Here is my current controller method.

def play_mp3
    t = TextToSpeech.new(current_user, "Play this text in the saved mp3 file")
    mp3_file = t.text_to_speech
end

<audio autoplay controls="controls">
<source src="/YOURMP3FILE.mp3" />
</audio>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM