vsrinivas commited on
Commit
62c2cbe
·
verified ·
1 Parent(s): 6c991f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -32,12 +32,12 @@ def extract_yt_audio(it, video_url, video_file):
32
  elif it == 'URL' and ("https://www" in video_url or "https://" in video_url or "www." in video_url):
33
  response = requests.get(video_url)
34
  video_data = io.BytesIO(response.content)
35
- output_stream = io.BytesIO()
36
- stream = ffmpeg.input('pipe:0')
37
- stream = ffmpeg.output(stream, 'pipe:1', format='wav')
38
- ffmpeg.run(stream, input=input_stream.read(), stdout=output_stream)
39
- output_stream.seek(0)
40
- sample = AudioSegment.from_file(output_stream, format="mp4")
41
  elif it == 'URL':
42
  sample = AudioSegment.from_file(video_url)
43
  else:
 
32
  elif it == 'URL' and ("https://www" in video_url or "https://" in video_url or "www." in video_url):
33
  response = requests.get(video_url)
34
  video_data = io.BytesIO(response.content)
35
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_file:
36
+ temp_file.write(video_data)
37
+ temp_file_path = temp_file.name
38
+ wav_file_path = temp_file_path.replace(".mp4", ".wav")
39
+ subprocess.run(["ffmpeg", "-i", temp_file_path, "-vn", "-acodec", "pcm_s16le", "-ar", "44100", "-ac", "2", wav_file_path])
40
+ sample = AudioSegment.from_wav(wav_file_path)
41
  elif it == 'URL':
42
  sample = AudioSegment.from_file(video_url)
43
  else: