speech-test commited on
Commit
c84d708
1 Parent(s): c0b3fb3

QOL updates

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +4 -2
  3. streaming.py +1 -4
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: YouTube Streaming ASR
3
- emoji: 💩
4
  colorFrom: red
5
  colorTo: red
6
  sdk: streamlit
 
1
  ---
2
  title: YouTube Streaming ASR
3
+ emoji: 📺
4
  colorFrom: red
5
  colorTo: red
6
  sdk: streamlit
app.py CHANGED
@@ -19,6 +19,8 @@ player_options = {
19
  "config": {"youtube": {"playerVars": {"start": 1}}},
20
  }
21
 
 
 
22
 
23
  @st.cache(hash_funcs={torch.nn.parameter.Parameter: lambda _: None})
24
  def load_model(model_path="facebook/wav2vec2-large-robust-ft-swbd-300h"):
@@ -75,7 +77,7 @@ def main():
75
  state.pad_duration_ms = st.slider("Padding duration (ms)", 100, 5000, 1000, 100)
76
  submit_button = st.form_submit_button(label="Submit")
77
 
78
- if submit_button or "asr_stream" not in state:
79
  # a hack to update the video player on value changes
80
  state.youtube_url = (
81
  state.youtube_url.split("&hash=")[0]
@@ -85,7 +87,7 @@ def main():
85
  state.youtube_url, state.chunk_duration_ms, state.pad_duration_ms
86
  )
87
  state.chunks_taken = 0
88
- state.lines = deque([], maxlen=3) # limit to the last 3 lines of subs
89
 
90
  player = st_player(state.youtube_url, **player_options, key="youtube_player")
91
 
 
19
  "config": {"youtube": {"playerVars": {"start": 1}}},
20
  }
21
 
22
+ # disable rapid fading in and out on `st.code` updates
23
+ st.markdown("<style>.element-container{opacity:1 !important}</style>", unsafe_allow_html=True)
24
 
25
  @st.cache(hash_funcs={torch.nn.parameter.Parameter: lambda _: None})
26
  def load_model(model_path="facebook/wav2vec2-large-robust-ft-swbd-300h"):
 
77
  state.pad_duration_ms = st.slider("Padding duration (ms)", 100, 5000, 1000, 100)
78
  submit_button = st.form_submit_button(label="Submit")
79
 
80
+ if submit_button:
81
  # a hack to update the video player on value changes
82
  state.youtube_url = (
83
  state.youtube_url.split("&hash=")[0]
 
87
  state.youtube_url, state.chunk_duration_ms, state.pad_duration_ms
88
  )
89
  state.chunks_taken = 0
90
+ state.lines = deque([], maxlen=5) # limit to the last 5 lines of subs
91
 
92
  player = st_player(state.youtube_url, **player_options, key="youtube_player")
93
 
streaming.py CHANGED
@@ -41,15 +41,13 @@ def ffmpeg_stream(youtube_url, sampling_rate=16_000, chunk_duration_ms=5000, pad
41
  except FileNotFoundError:
42
  raise ValueError("ffmpeg was not found but is required to stream audio files from filename")
43
 
44
- running = True
45
  acc = b""
46
  leftover = np.zeros((0,), dtype=np.float32)
47
- while running and ytdl_process.poll() is None:
48
  buflen = read_chunk_len * size_of_sample
49
 
50
  raw = ffmpeg_process.stdout.read(buflen)
51
  if raw == b"":
52
- running = False
53
  break
54
 
55
  if len(acc) + len(raw) > buflen:
@@ -61,7 +59,6 @@ def ffmpeg_stream(youtube_url, sampling_rate=16_000, chunk_duration_ms=5000, pad
61
  audio = np.concatenate([leftover, audio])
62
  if len(audio) < pad_len * 2:
63
  # TODO: handle end of stream better than this
64
- running = False
65
  break
66
  yield audio
67
 
 
41
  except FileNotFoundError:
42
  raise ValueError("ffmpeg was not found but is required to stream audio files from filename")
43
 
 
44
  acc = b""
45
  leftover = np.zeros((0,), dtype=np.float32)
46
+ while ytdl_process.poll() is None:
47
  buflen = read_chunk_len * size_of_sample
48
 
49
  raw = ffmpeg_process.stdout.read(buflen)
50
  if raw == b"":
 
51
  break
52
 
53
  if len(acc) + len(raw) > buflen:
 
59
  audio = np.concatenate([leftover, audio])
60
  if len(audio) < pad_len * 2:
61
  # TODO: handle end of stream better than this
 
62
  break
63
  yield audio
64