Neal Caren commited on
Commit
bf0ffa1
·
1 Parent(s): 9ec01b8

Works locally

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -9,7 +9,7 @@ import streamlit as st
9
 
10
  def speech_to_text(uploaded):
11
  model = whisper.load_model('tiny')
12
- result = model.transcribe(uploaded)
13
  return f'You said: {result["text"]}'
14
 
15
  def segment(nu_speakers):
@@ -28,15 +28,14 @@ def segment(nu_speakers):
28
 
29
  def audio_to_df(uploaded):
30
  monotize(uploaded)
31
- model = whisper.load_model('base')
32
  result = model.transcribe('mono.wav',verbose=True,
33
  without_timestamps=False)
34
  tdf = pd.DataFrame(result['segments'])
35
  return tdf
36
 
37
  def monotize(uploaded):
38
- print(uploaded.name)
39
- cmd = f"ffmpeg -y -i {uploaded.name} -acodec pcm_s16le -ar 16000 -ac 1 mono.wav"
40
  subprocess.Popen(cmd, shell=True).wait()
41
 
42
  def add_preface(row):
@@ -70,6 +69,7 @@ def transcribe(uploaded, nu_speakers):
70
 
71
  lines = []
72
  for row in binned_df['output'].values:
 
73
  lines.append(row)
74
 
75
  return '\n'.join(lines)
@@ -95,5 +95,9 @@ if submit:
95
  bytes_data = uploaded.getvalue()
96
  with open('temp_audio', 'wb') as outfile:
97
  outfile.write(bytes_data)
98
- speech_to_text('temp_audio')
 
 
 
 
99
  # To read file as bytes:
 
9
 
10
  def speech_to_text(uploaded):
11
  model = whisper.load_model('tiny')
12
+ result = model.transcribe(uploaded,verbose=True)
13
  return f'You said: {result["text"]}'
14
 
15
  def segment(nu_speakers):
 
28
 
29
  def audio_to_df(uploaded):
30
  monotize(uploaded)
31
+ model = whisper.load_model('tiny')
32
  result = model.transcribe('mono.wav',verbose=True,
33
  without_timestamps=False)
34
  tdf = pd.DataFrame(result['segments'])
35
  return tdf
36
 
37
  def monotize(uploaded):
38
+ cmd = f"ffmpeg -y -i {uploaded} -acodec pcm_s16le -ar 16000 -ac 1 mono.wav"
 
39
  subprocess.Popen(cmd, shell=True).wait()
40
 
41
  def add_preface(row):
 
69
 
70
  lines = []
71
  for row in binned_df['output'].values:
72
+ st.write(row)
73
  lines.append(row)
74
 
75
  return '\n'.join(lines)
 
95
  bytes_data = uploaded.getvalue()
96
  with open('temp_audio', 'wb') as outfile:
97
  outfile.write(bytes_data)
98
+ #st.write('Converting audio file.')
99
+ #monotize('temp_audio')
100
+ text = transcribe('temp_audio', nu_speakers)
101
+
102
+
103
  # To read file as bytes: