JBHF commited on
Commit
21d4955
1 Parent(s): c296411

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -47
app.py CHANGED
@@ -55,8 +55,49 @@
55
  # 08-04-2024
56
  #
57
 
 
 
 
 
 
 
 
 
 
 
58
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
 
 
 
 
 
 
60
 
61
 
62
  ###########################################################################################################
@@ -94,8 +135,13 @@ st.write("Ready Loading the WhisperModel: model = WhisperModel(model_size, devic
94
  # USING:
95
  # model = WhisperModel(model_size, device="cpu", compute_type="int8") # JB
96
  # segments, info = model.transcribe("sam_altman_lex_podcast_367.flac", beam_size=1)
 
97
  # /content/Ukrainian podcast #10 Traveling to Lviv - Подорож до Льова. SLOW UKRAINIAN.mp3
98
- segments, info = model.transcribe("Ukrainian podcast #10 Traveling to Lviv - Подорож до Льова. SLOW UKRAINIAN.mp3", beam_size=1)
 
 
 
 
99
  # print("Detected language '%s' with probability %f" % (info.language, info.language_probability))
100
  st.write("Detected language '%s' with probability %f" % (info.language, info.language_probability))
101
  st.write("")
@@ -116,18 +162,20 @@ seconds = 233.8249375 - minutes*60
116
  st.write(minutes," minutes and ", seconds, " seconds")
117
 
118
 
 
119
  for segment in segments:
120
  # print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
121
  st.write("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
 
122
 
123
  st.write("---------------------------------------------------------------------")
124
 
125
- text_to_transcribe = ""
126
- st.write("TOTAL TEXT TO TRANSCRIBE:")
127
- for segment in segments:
128
- st.write(segment.text)
129
- text_to_transcribe = text_to_transcribe + " " + segment
130
- # print(segment)
131
 
132
  st.write("text_to_transcribe: ", text_to_transcribe)
133
 
@@ -135,43 +183,3 @@ st.write("text_to_transcribe: ", text_to_transcribe)
135
  ###########################################################################################################
136
 
137
 
138
- #
139
- # Installation:
140
- # pip install streamlit-audiorecorder
141
- # Note: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.
142
- #
143
- # On ubuntu/debian: sudo apt update && sudo apt install ffmpeg
144
- # On mac: brew install ffmpeg
145
-
146
- import streamlit as st
147
- from audiorecorder import audiorecorder
148
-
149
- st.title("Audio Recorder")
150
- # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
151
- audio = audiorecorder("Click to record", "Click to stop recording", "Click to pause recording")
152
-
153
-
154
- # JB:
155
- # https://docs.streamlit.io/develop/concepts/architecture/caching
156
- # @st.cache_data
157
- @st.cache_resource # 👈 Add the caching decorator
158
- def audio_export(audio_wav_file, format):
159
- # audio.export("audio.wav", format="wav") # ORIGINAL
160
- audio.export(audio_wav_file, format=format)
161
-
162
- if len(audio) > 0:
163
- # To play audio in frontend:
164
- st.audio(audio.export().read())
165
-
166
- # To save audio to a file, use pydub export method:
167
- # https://docs.streamlit.io/develop/concepts/architecture/caching
168
- # @st.cache_data
169
- # @st.cache_data
170
- # audio.export("audio.wav", format="wav") # ORIGINAL
171
- audio_export("audio.wav", format="wav") # JB 08-04-2024
172
-
173
- # To get audio properties, use pydub AudioSegment properties:
174
- st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
175
-
176
-
177
- st.button("Rerun")
 
55
  # 08-04-2024
56
  #
57
 
58
+
59
+ ###########################################################################################################
60
+ #
61
+ # Installation:
62
+ # pip install streamlit-audiorecorder
63
+ # Note: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.
64
+ #
65
+ # On ubuntu/debian: sudo apt update && sudo apt install ffmpeg
66
+ # On mac: brew install ffmpeg
67
+
68
  import streamlit as st
69
+ from audiorecorder import audiorecorder
70
+
71
+ st.title("Audio Recorder")
72
+ # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
73
+ audio = audiorecorder("Click to record", "Click to stop recording", "Click to pause recording")
74
+
75
+
76
+ # JB:
77
+ # https://docs.streamlit.io/develop/concepts/architecture/caching
78
+ # @st.cache_data
79
+ @st.cache_resource # 👈 Add the caching decorator
80
+ def audio_export(audio_wav_file, format):
81
+ # audio.export("audio.wav", format="wav") # ORIGINAL
82
+ audio.export(audio_wav_file, format=format)
83
+
84
+ if len(audio) > 0:
85
+ # To play audio in frontend:
86
+ st.audio(audio.export().read())
87
+
88
+ # To save audio to a file, use pydub export method:
89
+ # https://docs.streamlit.io/develop/concepts/architecture/caching
90
+ # @st.cache_data
91
+ # @st.cache_data
92
+ # audio.export("audio.wav", format="wav") # ORIGINAL
93
+ audio_export("audio.wav", format="wav") # JB 08-04-2024
94
 
95
+ # To get audio properties, use pydub AudioSegment properties:
96
+ st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
97
+
98
+
99
+ st.button("Rerun")
100
+ ###########################################################################################################
101
 
102
 
103
  ###########################################################################################################
 
135
  # USING:
136
  # model = WhisperModel(model_size, device="cpu", compute_type="int8") # JB
137
  # segments, info = model.transcribe("sam_altman_lex_podcast_367.flac", beam_size=1)
138
+
139
  # /content/Ukrainian podcast #10 Traveling to Lviv - Подорож до Льова. SLOW UKRAINIAN.mp3
140
+ # segments, info = model.transcribe("Ukrainian podcast #10 Traveling to Lviv - Подорож до Льова. SLOW UKRAINIAN.mp3", beam_size=1)
141
+ # TEST:
142
+ segments, info = model.transcribe("audio.wav", beam_size=1)
143
+
144
+
145
  # print("Detected language '%s' with probability %f" % (info.language, info.language_probability))
146
  st.write("Detected language '%s' with probability %f" % (info.language, info.language_probability))
147
  st.write("")
 
162
  st.write(minutes," minutes and ", seconds, " seconds")
163
 
164
 
165
+ text_to_transcribe = ""
166
  for segment in segments:
167
  # print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
168
  st.write("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
169
+ text_to_transcribe = text_to_transcribe + " " + segment
170
 
171
  st.write("---------------------------------------------------------------------")
172
 
173
+ #text_to_transcribe = ""
174
+ #st.write("TOTAL TEXT TO TRANSCRIBE:")
175
+ #for segment in segments:
176
+ # st.write(segment.text)
177
+ # text_to_transcribe = text_to_transcribe + " " + segment
178
+ # # print(segment)
179
 
180
  st.write("text_to_transcribe: ", text_to_transcribe)
181
 
 
183
  ###########################################################################################################
184
 
185