mirror of
https://github.com/snakers4/silero-vad.git
synced 2026-02-05 18:09:22 +08:00
fx old examples
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"#!apt install ffmpeg\n",
|
||||||
"!pip -q install pydub\n",
|
"!pip -q install pydub\n",
|
||||||
"from google.colab import output\n",
|
"from google.colab import output\n",
|
||||||
"from base64 import b64decode, b64encode\n",
|
"from base64 import b64decode, b64encode\n",
|
||||||
@@ -37,13 +38,12 @@
|
|||||||
" model='silero_vad',\n",
|
" model='silero_vad',\n",
|
||||||
" force_reload=True)\n",
|
" force_reload=True)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def int2float(sound):\n",
|
"def int2float(audio):\n",
|
||||||
" abs_max = np.abs(sound).max()\n",
|
" samples = audio.get_array_of_samples()\n",
|
||||||
" sound = sound.astype('float32')\n",
|
" new_sound = audio._spawn(samples)\n",
|
||||||
" if abs_max > 0:\n",
|
" arr = np.array(samples).astype(np.float32)\n",
|
||||||
" sound *= 1/32768\n",
|
" arr = arr / np.abs(arr).max()\n",
|
||||||
" sound = sound.squeeze()\n",
|
" return arr\n",
|
||||||
" return sound\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"AUDIO_HTML = \"\"\"\n",
|
"AUDIO_HTML = \"\"\"\n",
|
||||||
"<script>\n",
|
"<script>\n",
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
" audio.export('test.mp3', format='mp3')\n",
|
" audio.export('test.mp3', format='mp3')\n",
|
||||||
" audio = audio.set_channels(1)\n",
|
" audio = audio.set_channels(1)\n",
|
||||||
" audio = audio.set_frame_rate(16000)\n",
|
" audio = audio.set_frame_rate(16000)\n",
|
||||||
" audio_float = int2float(np.array(audio.get_array_of_samples()))\n",
|
" audio_float = int2float(audio)\n",
|
||||||
" audio_tens = torch.tensor(audio_float)\n",
|
" audio_tens = torch.tensor(audio_float)\n",
|
||||||
" return audio_tens\n",
|
" return audio_tens\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -158,8 +158,7 @@
|
|||||||
" line.set_data(x, y)\n",
|
" line.set_data(x, y)\n",
|
||||||
" line.set_color('#990000')\n",
|
" line.set_color('#990000')\n",
|
||||||
" return line,\n",
|
" return line,\n",
|
||||||
"\n",
|
" anim = FuncAnimation(fig, animate, init_func=init, interval=interval, save_count=int(audio_duration / (interval / 1000)))\n",
|
||||||
" anim = FuncAnimation(fig, animate, init_func=init, interval=interval, save_count=audio_duration / (interval / 1000))\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" f = r\"animation.mp4\"\n",
|
" f = r\"animation.mp4\"\n",
|
||||||
" writervideo = FFMpegWriter(fps=1000/interval)\n",
|
" writervideo = FFMpegWriter(fps=1000/interval)\n",
|
||||||
@@ -174,15 +173,10 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"def record_make_animation():\n",
|
"def record_make_animation():\n",
|
||||||
" tensor = record()\n",
|
" tensor = record()\n",
|
||||||
"\n",
|
|
||||||
" print('Calculating probabilities...')\n",
|
" print('Calculating probabilities...')\n",
|
||||||
" speech_probs = []\n",
|
" speech_probs = []\n",
|
||||||
" window_size_samples = 512\n",
|
" window_size_samples = 512\n",
|
||||||
" for i in range(0, len(tensor), window_size_samples):\n",
|
" speech_probs = model.audio_forward(tensor, sr=16000)[0].tolist()\n",
|
||||||
" if len(tensor[i: i+ window_size_samples]) < window_size_samples:\n",
|
|
||||||
" break\n",
|
|
||||||
" speech_prob = model(tensor[i: i+ window_size_samples], 16000).item()\n",
|
|
||||||
" speech_probs.append(speech_prob)\n",
|
|
||||||
" model.reset_states()\n",
|
" model.reset_states()\n",
|
||||||
" print('Making animation...')\n",
|
" print('Making animation...')\n",
|
||||||
" make_animation(speech_probs, len(tensor) / 16000)\n",
|
" make_animation(speech_probs, len(tensor) / 16000)\n",
|
||||||
@@ -196,7 +190,9 @@
|
|||||||
" <video width=800 controls>\n",
|
" <video width=800 controls>\n",
|
||||||
" <source src=\"%s\" type=\"video/mp4\">\n",
|
" <source src=\"%s\" type=\"video/mp4\">\n",
|
||||||
" </video>\n",
|
" </video>\n",
|
||||||
" \"\"\" % data_url))"
|
" \"\"\" % data_url))\n",
|
||||||
|
"\n",
|
||||||
|
" return speech_probs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -216,7 +212,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"record_make_animation()"
|
"speech_probs = record_make_animation()"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user