Kevin676 commited on
Commit
eeeccc0
·
1 Parent(s): 04f2289

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -5,19 +5,21 @@ model = whisper.load_model("small")
5
  import torch
6
  import torchaudio
7
  from speechbrain.pretrained import SpectralMaskEnhancement
 
 
8
  import gradio as gr
9
  import openai
10
 
11
  mes1 = [
12
- {"role": "system", "content": "You are a TOEFL examiner. Help me improve my oral Englsih and give me feedback. Replace the Arabic numerals with the corresponding English words in your response."}
13
  ]
14
 
15
  mes2 = [
16
- {"role": "system", "content": "You are a mental health therapist. Your name is Tina. Replace the Arabic numerals with the corresponding English words in your response."}
17
  ]
18
 
19
  mes3 = [
20
- {"role": "system", "content": "You are my personal assistant. Your name is Alice. Replace the Arabic numerals with the corresponding English words in your response."}
21
  ]
22
 
23
  res = []
@@ -80,8 +82,16 @@ def transcribe(apikey, upload, audio, choice1):
80
 
81
  enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
82
  torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
 
 
 
 
 
 
 
 
83
 
84
- return [result.text, chat_response, "enhanced.wav"]
85
 
86
  output_1 = gr.Textbox(label="Speech to Text")
87
  output_2 = gr.Textbox(label="ChatGPT Output")
 
5
  import torch
6
  import torchaudio
7
  from speechbrain.pretrained import SpectralMaskEnhancement
8
+ from scipy.io import wavfile
9
+ import noisereduce as nr
10
  import gradio as gr
11
  import openai
12
 
13
  mes1 = [
14
+ {"role": "system", "content": "You are a TOEFL examiner. Help me improve my oral Englsih and give me feedback."}
15
  ]
16
 
17
  mes2 = [
18
+ {"role": "system", "content": "You are a mental health therapist. Your name is Tina."}
19
  ]
20
 
21
  mes3 = [
22
+ {"role": "system", "content": "You are my personal assistant. Your name is Alice."}
23
  ]
24
 
25
  res = []
 
82
 
83
  enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
84
  torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
85
+
86
+ rate, data = wavfile.read("enhanced.wav")
87
+
88
+ reduced_noise = nr.reduce_noise(y=data, sr=rate, stationary=True)
89
+ #reduced_noise = nr.reduce_noise(y = data, sr=rate, prop_decrease= 0.85)
90
+ #reduced_noise = nr.reduce_noise(y = data, sr=rate, thresh_n_mult_nonstationary=2, stationary=False)
91
+
92
+ wavfile.write("audio1.wav", rate, reduced_noise)
93
 
94
+ return [result.text, chat_response, "audio1.wav"]
95
 
96
  output_1 = gr.Textbox(label="Speech to Text")
97
  output_2 = gr.Textbox(label="ChatGPT Output")