Skip to content

Instantly share code, notes, and snippets.

@hosackm
Created September 2, 2015 22:30

Revisions

  1. hosackm created this gist Sep 2, 2015.
    28 changes: 28 additions & 0 deletions flaskaudiostream.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    from flask import Flask, Response

    app = Flask(__name__)


    @app.route("/wav")
    def streamwav():
    def generate():
    with open("signals/song.wav", "rb") as fwav:
    data = fwav.read(1024)
    while data:
    yield data
    data = fwav.read(1024)
    return Response(generate(), mimetype="audio/x-wav")


    @app.route("/ogg")
    def streamogg():
    def generate():
    with open("signals/song.ogg", "rb") as fogg:
    data = fogg.read(1024)
    while data:
    yield data
    data = fogg.read(1024)
    return Response(generate(), mimetype="audio/ogg")

    if __name__ == "__main__":
    app.run(debug=True)