149 строки
3.3 KiB
Plaintext
149 строки
3.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "4a7b2b90-a1d4-4dbd-a75c-d77dfbda2718",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import requests\n",
|
|
"import soundfile as sf\n",
|
|
"import base64\n",
|
|
"import json\n",
|
|
"import os"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "e9409bda",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# To get a username and auth token, please message plc_challenge@microsoft.com\n",
|
|
"PLCMOS_USER = \"enter your username here\"\n",
|
|
"PLCMOS_AUTH_TOKEN = \"enter your auth token here\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "264141c9-1abb-420e-a183-4cf456bdb1b0",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'OK'"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"API_BASE_URL = \"https://dnsmos.azurewebsites.net/\"\n",
|
|
"resp = requests.get(API_BASE_URL + \"health\")\n",
|
|
"resp.text"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "dbb11ef7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"healed_path = \"challenge_data/test/healed_signals\"\n",
|
|
"reference_path = \"challenge_data/test/clean_signals\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "f196d7fd-f8ec-4d80-81b3-68ef8a7c3f71",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"in_name = \"40.wav\"\n",
|
|
"audio, sr = sf.read(os.path.join(healed_path, in_name))\n",
|
|
"assert sr == 16000\n",
|
|
"\n",
|
|
"audio_clean, sr = sf.read(os.path.join(reference_path, in_name))\n",
|
|
"assert sr == 16000"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "02c135f8-a2e9-4a84-886c-6b0a0e6bf827",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"headers = {\n",
|
|
" 'Content-Type': 'application/json',\n",
|
|
" 'Authorization': 'Basic ' + base64.b64encode((PLCMOS_USER + \":\" + PLCMOS_AUTH_TOKEN).encode(\"utf-8\")).decode(\"utf-8\")\n",
|
|
"}\n",
|
|
"data = {\n",
|
|
" \"degraded\": audio.tolist(), \n",
|
|
" \"reference\": audio_clean.tolist(), \n",
|
|
" \"filename\": os.path.basename(in_name),\n",
|
|
"}\n",
|
|
"resp = requests.post(API_BASE_URL + \"score-plc\", data=json.dumps(data), headers=headers)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "15eeef35-ba7b-40df-b521-286c5d9f9969",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'model_version': 1, 'plc_mos': 1.7383243441581726}"
|
|
]
|
|
},
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"resp.json()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "16e34607",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|