Commit d9b9bddb authored by Andre Julius's avatar Andre Julius 👀
Browse files

Add playing functionality. No error checking yet.

parent 67d08fe8
import wave
import pyaudio
import api.index
from config import datadir
sound = wave.open("data/test.wav")
p = pyaudio.PyAudio()
chunk = 1024
stream = p.open(format=p.get_format_from_width(sound.getsampwidth()),
channels=sound.getnchannels(),
rate=sound.getframerate(),
output=True)
data = sound.readframes(chunk)
while data != '':
stream.write(data)
data = sound.readframes(chunk)
def play(filename):
if api.index.is_indexed(filename):
wave_file = wave.open(datadir + "/" + filename)
p = pyaudio.PyAudio()
chunk = 1024
stream = p.open(
format=p.get_format_from_width(
wave_file.getsampwidth()
),
channels=wave_file.getnchannels(),
rate=wave_file.getframerate(),
output=True
)
data = wave_file.readframes(chunk)
while data != '':
stream.write(data)
data = wave_file.readframes(chunk)
from flask import redirect, abort, request, jsonify, Response
from web import web
import api.index
import api.player
@web.route('/', defaults={'path': ''})
......@@ -15,3 +16,8 @@ def catch_all(path):
@web.route("/index/")
def index():
return jsonify(api.index.index)
@web.route("/play/<file>")
def play(file):
api.player.play(file)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment