123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- from typing import Union
- from fairseq import tasks
- from fairseq.data.dictionary import Dictionary
- from fastapi import FastAPI, File, UploadFile
- from pydantic import BaseModel
- import logging
- import argparse
- import torch
- import torch.nn as nn
- import pickle
- import soundfile as sf
- import torch.nn.functional as F
- import yaml
- import os, sys
- import numpy as np
- from inference import inference, inference_file, inference_online
- logging.basicConfig()
- logging.root.setLevel(logging.INFO)
- logging.basicConfig(level=logging.INFO)
- logger = logging.getLogger(__name__)
- class Recording(BaseModel):
- filename: str
- content_type: str
- content: list
- class AudioClip(BaseModel):
- device: str
- time: str
- recording: Recording
- app = FastAPI()
- @app.get("/")
- def root():
- return {"message" : "Hello World!!!"}
- @app.post("/test")
- def post_test(audioClip: AudioClip):
- output = ""
- print("input audio? = ", type(audioClip.recording.content))
- audio = np.array(audioClip.recording.content).squeeze()
- print("in test func, audio = ", type(audio), audio.shape)
- feats = get_feature(audio)
- print("in test section, feats = ", type(feats), feats.shape)
- output = inference(feats)
- return {"output" : output}
- @app.post("/inference")
- def post_inference(audioClip: AudioClip):
- output = inference(audioClip.recording.content)
- return {"output" : output}
- @app.post("/online")
- def post_inference(audioClip: AudioClip):
- output = inference_online(audioClip.recording.content)
- return {"output" : output}
- @app.post("/inference_file")
- def post_inference_file():
-
- '''
- control formatting
- if data.format != 'wav':
- do_formatting()
- '''
-
- print('in Inference Start')
- output = ''
- output = inference_file()
-
- return {"output" : output}
- if __name__ == '__main__':
- print('this is main')
- print(inference(args["wav_path"]))
|