File size: 3,156 Bytes
93a0cf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from audio_utils import audio_stream_generator\n",
    "import  IPython.display as ipd\n",
    "import sys\n",
    "sys.path.append(\"..\")\n",
    "from transcribe.helpers.vadprocessor import FixedVADIterator\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "vac = FixedVADIterator(\n",
    "                threshold=0.5,\n",
    "                sampling_rate=16000,\n",
    "                # speech_pad_ms=10\n",
    "                min_silence_duration_ms = 100,\n",
    "                # speech_pad_ms = 30,\n",
    "                max_speech_duration_s=5.0,\n",
    "                )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "SAMPLE_FILE_PATH = \"/Users/david/Samples/Audio/zh/liyongle.wav\"\n",
    "SAMPLING_RATE = 16000\n",
    "\n",
    "chunks_generator =  audio_stream_generator(SAMPLE_FILE_PATH, chunk_size=4096)\n",
    "vac.reset_states()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已加载音频文件: /Users/david/Samples/Audio/zh/liyongle.wav\n",
      "采样率: 16000 Hz\n",
      "音频长度: 64.00 秒\n",
      "{'start': 3616}\n",
      "{'end': 83968}\n",
      "{'end': 164352}\n",
      "{'end': 244736}\n",
      "{'end': 325120}\n",
      "{'end': 405504}\n",
      "{'end': 485888}\n",
      "{'end': 566272}\n",
      "{'end': 624608}\n",
      "{'start': 631328}\n",
      "{'end': 691168}\n",
      "{'start': 698912}\n",
      "{'end': 779264}\n",
      "{'end': 800736}\n",
      "{'start': 805920}\n",
      "{'end': 846816}\n",
      "{'start': 855072}\n",
      "{'end': 862176}\n",
      "{'start': 864288}\n",
      "{'end': 890336}\n",
      "{'start': 893984}\n",
      "{'end': 912352}\n",
      "{'start': 917536}\n",
      "{'end': 932320}\n",
      "{'start': 939040}\n",
      "{'end': 966112}\n",
      "{'start': 970784}\n",
      "{'end': 1015264}\n",
      "{'start': 1019424}\n",
      "音频流处理完成\n"
     ]
    }
   ],
   "source": [
    "for chunk in chunks_generator:\n",
    "    # vad_iterator.reset_states()\n",
    "    # audio_buffer = np.append(audio_buffer, chunk)\n",
    "    \n",
    "    speech_dict = vac(chunk, return_seconds=False)\n",
    "    if speech_dict:\n",
    "        print(speech_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}