Web server release v2 (#99)
* Init App * init server.py (#93) * init server.py * Update requirements.txt Add requirement Co-authored-by: auau <auau@test.com> Co-authored-by: babysor00 <babysor00@gmail.com> * Run web.py! Run web.py! * Restruct readme and add instruction to use web server * fix training preprocess of vocoder * Init App * init server.py (#93) * init server.py * Update requirements.txt Add requirement Co-authored-by: auau <auau@test.com> Co-authored-by: babysor00 <babysor00@gmail.com> * Run web.py! Run web.py! * fix training preprocess of vocoder * Refactor to restful style Co-authored-by: balala <Ozgay@users.noreply.github.com> Co-authored-by: auau <auau@test.com>pull/102/head
parent
4acfee2a64
commit
0d0b55d3e9
@ -0,0 +1,14 @@
|
||||
from flask import Blueprint
|
||||
from flask_restx import Api
|
||||
from .audio import api as audio
|
||||
|
||||
api_blueprint = Blueprint('api', __name__, url_prefix='/api')
|
||||
|
||||
api = Api(
|
||||
app=api_blueprint,
|
||||
title='Mocking Bird',
|
||||
version='1.0',
|
||||
description='My API'
|
||||
)
|
||||
|
||||
api.add_namespace(audio)
|
@ -0,0 +1,43 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from flask_restx import Namespace, Resource, fields
|
||||
from flask import Response, current_app
|
||||
|
||||
api = Namespace('audios', description='Audios related operations')
|
||||
|
||||
audio = api.model('Audio', {
|
||||
'name': fields.String(required=True, description='The audio name'),
|
||||
})
|
||||
|
||||
def generate(wav_path):
|
||||
with open(wav_path, "rb") as fwav:
|
||||
data = fwav.read(1024)
|
||||
while data:
|
||||
yield data
|
||||
data = fwav.read(1024)
|
||||
|
||||
@api.route('/')
|
||||
class AudioList(Resource):
|
||||
@api.doc('list_audios')
|
||||
@api.marshal_list_with(audio)
|
||||
def get(self):
|
||||
'''List all audios'''
|
||||
audio_samples = []
|
||||
AUDIO_SAMPLES_DIR = current_app.config.get("AUDIO_SAMPLES_DIR")
|
||||
if os.path.isdir(AUDIO_SAMPLES_DIR):
|
||||
audio_samples = list(Path(AUDIO_SAMPLES_DIR).glob("*.wav"))
|
||||
return list(a.name for a in audio_samples)
|
||||
|
||||
@api.route('/<name>')
|
||||
@api.param('name', 'The name of audio')
|
||||
@api.response(404, 'audio not found')
|
||||
class Audio(Resource):
|
||||
@api.doc('get_audio')
|
||||
@api.marshal_with(audio)
|
||||
def get(self, name):
|
||||
'''Fetch a cat given its identifier'''
|
||||
AUDIO_SAMPLES_DIR = current_app.config.get("AUDIO_SAMPLES_DIR")
|
||||
if Path(AUDIO_SAMPLES_DIR + name).exists():
|
||||
return Response(generate(AUDIO_SAMPLES_DIR + name), mimetype="audio/x-wav")
|
||||
api.abort(404)
|
||||
|
Loading…
Reference in New Issue