diff --git a/demos/audio_searching/README.md b/demos/audio_searching/README.md index 87a1956b9fd22b1d5f71d33794839e5d2817d5c1..e829d991aa9863259d20b07c9dc6af664eb8dc27 100644 --- a/demos/audio_searching/README.md +++ b/demos/audio_searching/README.md @@ -167,8 +167,8 @@ Then to start the system server, and it provides HTTP backend services. [2022-03-26 22:54:08,633] [ INFO] - embedding size: (192,) Extracting feature from audio No. 2 , 20 audios in total ... - 2022-03-26 22:54:15,892 | INFO | main.py | load_audios | 85 | Successfully loaded data, total count: 20 - 2022-03-26 22:54:15,908 | INFO | main.py | count_audio | 148 | Successfully count the number of data! + 2022-03-26 22:54:15,892 | INFO | audio_search.py | load_audios | 85 | Successfully loaded data, total count: 20 + 2022-03-26 22:54:15,908 | INFO | audio_search.py | count_audio | 148 | Successfully count the number of data! [2022-03-26 22:54:15,916] [ INFO] - checking the aduio file format...... [2022-03-26 22:54:15,916] [ INFO] - The sample rate is 16000 [2022-03-26 22:54:15,916] [ INFO] - The audio file format is right @@ -183,12 +183,12 @@ Then to start the system server, and it provides HTTP backend services. [2022-03-26 22:54:15,924] [ INFO] - feats shape:[1, 80, 53], lengths shape: [1] [2022-03-26 22:54:16,051] [ INFO] - embedding size: (192,) ... - 2022-03-26 22:54:16,086 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/test.wav, score 100.0 - 2022-03-26 22:54:16,087 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_chopping.wav, score 29.182177782058716 - 2022-03-26 22:54:16,087 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_cut_into_body.wav, score 22.73637056350708 + 2022-03-26 22:54:16,086 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/test.wav, score 100.0 + 2022-03-26 22:54:16,087 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_chopping.wav, score 29.182177782058716 + 2022-03-26 22:54:16,087 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_cut_into_body.wav, score 22.73637056350708 ... - 2022-03-26 22:54:16,088 | INFO | main.py | search_local_audio | 136 | Successfully searched similar audio! - 2022-03-26 22:54:17,164 | INFO | main.py | drop_tables | 160 | Successfully drop tables in Milvus and MySQL! + 2022-03-26 22:54:16,088 | INFO | audio_search.py | search_local_audio | 136 | Successfully searched similar audio! + 2022-03-26 22:54:17,164 | INFO | audio_search.py | drop_tables | 160 | Successfully drop tables in Milvus and MySQL! ``` - GUI test (Optional) diff --git a/demos/audio_searching/README_cn.md b/demos/audio_searching/README_cn.md index a93dbdc1f4585c35a86121b8a2629f7854cbed46..c13742af7a1613a089e1e14c069ec7a3340dd669 100644 --- a/demos/audio_searching/README_cn.md +++ b/demos/audio_searching/README_cn.md @@ -169,8 +169,8 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…" [2022-03-26 22:54:08,633] [ INFO] - embedding size: (192,) Extracting feature from audio No. 2 , 20 audios in total ... - 2022-03-26 22:54:15,892 | INFO | main.py | load_audios | 85 | Successfully loaded data, total count: 20 - 2022-03-26 22:54:15,908 | INFO | main.py | count_audio | 148 | Successfully count the number of data! + 2022-03-26 22:54:15,892 | INFO | audio_search.py | load_audios | 85 | Successfully loaded data, total count: 20 + 2022-03-26 22:54:15,908 | INFO | audio_search.py | count_audio | 148 | Successfully count the number of data! [2022-03-26 22:54:15,916] [ INFO] - checking the aduio file format...... [2022-03-26 22:54:15,916] [ INFO] - The sample rate is 16000 [2022-03-26 22:54:15,916] [ INFO] - The audio file format is right @@ -185,12 +185,12 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…" [2022-03-26 22:54:15,924] [ INFO] - feats shape:[1, 80, 53], lengths shape: [1] [2022-03-26 22:54:16,051] [ INFO] - embedding size: (192,) ... - 2022-03-26 22:54:16,086 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/test.wav, score 100.0 - 2022-03-26 22:54:16,087 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_chopping.wav, score 29.182177782058716 - 2022-03-26 22:54:16,087 | INFO | main.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_cut_into_body.wav, score 22.73637056350708 + 2022-03-26 22:54:16,086 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/test.wav, score 100.0 + 2022-03-26 22:54:16,087 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_chopping.wav, score 29.182177782058716 + 2022-03-26 22:54:16,087 | INFO | audio_search.py | search_local_audio | 132 | search result http://testserver/data?audio_path=./example_audio/knife_cut_into_body.wav, score 22.73637056350708 ... - 2022-03-26 22:54:16,088 | INFO | main.py | search_local_audio | 136 | Successfully searched similar audio! - 2022-03-26 22:54:17,164 | INFO | main.py | drop_tables | 160 | Successfully drop tables in Milvus and MySQL! + 2022-03-26 22:54:16,088 | INFO | audio_search.py | search_local_audio | 136 | Successfully searched similar audio! + 2022-03-26 22:54:17,164 | INFO | audio_search.py | drop_tables | 160 | Successfully drop tables in Milvus and MySQL! ``` - 前端测试(可选) diff --git a/demos/audio_searching/src/test_vpr_search.py b/demos/audio_searching/src/test_vpr_search.py index 8cc8dc8412e76d92ac04219c52cb940643df62b9..298e12ebaf2b4408f67df3e9fe16f6fd59cb6219 100644 --- a/demos/audio_searching/src/test_vpr_search.py +++ b/demos/audio_searching/src/test_vpr_search.py @@ -73,7 +73,9 @@ def test_data(spk: str): """ Get the audio file by spk_id in MySQL """ - response = client.get("/vpr/data?spk_id=" + spk) + response = client.get( + "/vpr/data", + json={"spk_id": spk}, ) assert response.status_code == 200 @@ -81,7 +83,9 @@ def test_del(spk: str): """ Delete the record in MySQL by spk_id """ - response = client.post("/vpr/del?spk_id=" + spk) + response = client.post( + "/vpr/del", + json={"spk_id": spk}, ) assert response.status_code == 200 diff --git a/demos/audio_searching/src/vpr_search.py b/demos/audio_searching/src/vpr_search.py index 8e702221c8bc23213533654aa7d6545e91f5631b..94974d0d8d28c4de6c4ff873c58aef7035198bef 100644 --- a/demos/audio_searching/src/vpr_search.py +++ b/demos/audio_searching/src/vpr_search.py @@ -17,8 +17,8 @@ import uvicorn from config import UPLOAD_PATH from fastapi import FastAPI from fastapi import File +from fastapi import Form from fastapi import UploadFile -from logs import LOGGER from mysql_helpers import MySQLHelper from operations.count import do_count_vpr from operations.count import do_get @@ -31,6 +31,8 @@ from starlette.middleware.cors import CORSMiddleware from starlette.requests import Request from starlette.responses import FileResponse +from logs import LOGGER + app = FastAPI() app.add_middleware( CORSMiddleware, @@ -49,10 +51,12 @@ if not os.path.exists(UPLOAD_PATH): @app.post('/vpr/enroll') async def vpr_enroll(table_name: str=None, - spk_id: str=None, + spk_id: str=Form(...), audio: UploadFile=File(...)): # Enroll the uploaded audio with spk-id into MySQL try: + if not spk_id: + return {'status': False, 'msg': "spk_id can not be None"} # Save the upload data to server. content = await audio.read() audio_path = os.path.join(UPLOAD_PATH, audio.filename) @@ -63,7 +67,7 @@ async def vpr_enroll(table_name: str=None, return {'status': True, 'msg': "Successfully enroll data!"} except Exception as e: LOGGER.error(e) - return {'status': False, 'msg': e}, 400 + return {'status': False, 'msg': e} @app.post('/vpr/enroll/local') @@ -128,9 +132,12 @@ async def vpr_recog_local(request: Request, @app.post('/vpr/del') -async def vpr_del(table_name: str=None, spk_id: str=None): +async def vpr_del(table_name: str=None, spk_id: dict=None): # Delete a record by spk_id in MySQL try: + spk_id = spk_id['spk_id'] + if not spk_id: + return {'status': False, 'msg': "spk_id can not be None"} do_delete(table_name, spk_id, MYSQL_CLI) LOGGER.info("Successfully delete a record by spk_id in MySQL") return {'status': True, 'msg': "Successfully delete data!"} @@ -156,9 +163,12 @@ async def vpr_list(table_name: str=None): @app.get('/vpr/data') async def vpr_data( table_name: str=None, - spk_id: str=None, ): + spk_id: dict=None, ): # Get the audio file from path by spk_id in MySQL try: + spk_id = spk_id['spk_id'] + if not spk_id: + return {'status': False, 'msg': "spk_id can not be None"} audio_path = do_get(table_name, spk_id, MYSQL_CLI) LOGGER.info(f"Successfully get audio path {audio_path}!") return FileResponse(audio_path)