MufinApps commited on
Commit
cfbbaa5
·
1 Parent(s): a05c6d9

Remove noise detection

Browse files
Files changed (1) hide show
  1. app.py +6 -21
app.py CHANGED
@@ -1,7 +1,10 @@
1
  import gradio as gr
2
  import openai
3
  import threading as th
 
4
 
 
 
5
 
6
 
7
  def translateoutput(text,language):
@@ -78,29 +81,11 @@ language_info={
78
  'Other': 'Other'
79
  }
80
 
81
- import librosa
82
- import noisereduce as nr
83
- from pydub import AudioSegment
84
-
85
- def enhance_and_denoise_audio(file_path):
86
- # Load the audio file
87
- data, rate = librosa.load(file_path, sr=None)
88
-
89
- # Perform noise reduction
90
- reduced_noise_audio = nr.reduce_noise(y=data, sr=rate)
91
-
92
- # Increase the volume by 10 dB (using PyDub)
93
- audio_segment = AudioSegment(reduced_noise_audio.tobytes(), frame_rate=rate, sample_width=reduced_noise_audio.dtype.itemsize, channels=1)
94
- enhanced_audio = audio_segment + 10
95
-
96
- # Export the enhanced audio to the same file
97
- enhanced_audio.export(file_path, format="wav")
98
-
99
- return file_path
100
 
101
  def translate(audio_file,lan):
102
  message=""
103
- audio_file=enhance_and_denoise_audio(audio_file)
104
  with open(audio_file, 'rb') as f:
105
  result = openai.Audio.translate("whisper-1", f)
106
  text=result.text
@@ -117,7 +102,7 @@ def translate(audio_file,lan):
117
 
118
  def transcription(audio_file,input_lang):
119
  global language_info
120
- audio_file=enhance_and_denoise_audio(audio_file)
121
  with open(audio_file, 'rb') as f:
122
  if input_lang=="Other":
123
  result = openai.Audio.transcribe("whisper-1", f)
 
1
  import gradio as gr
2
  import openai
3
  import threading as th
4
+ import os
5
 
6
+ os.environ['OPENAI_API_KEY']="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"
7
+ openai.api_key = os.environ['OPENAI_API_KEY']
8
 
9
 
10
  def translateoutput(text,language):
 
81
  'Other': 'Other'
82
  }
83
 
84
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  def translate(audio_file,lan):
87
  message=""
88
+
89
  with open(audio_file, 'rb') as f:
90
  result = openai.Audio.translate("whisper-1", f)
91
  text=result.text
 
102
 
103
  def transcription(audio_file,input_lang):
104
  global language_info
105
+
106
  with open(audio_file, 'rb') as f:
107
  if input_lang=="Other":
108
  result = openai.Audio.transcribe("whisper-1", f)