ychenNLP commited on
Commit
0648a36
1 Parent(s): 51a9e4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -10,19 +10,23 @@ def asr(url):
10
  ydl_opts = {
11
  'format': 'bestaudio/best',
12
  'outtmpl': 'audio_downloaded.%(ext)s',
13
- 'ignoreerrors': True,
14
  'no_continue': True,
15
  }
16
 
17
-
18
  # Create a youtube-dl object
19
  ydl = yt_dlp.YoutubeDL(ydl_opts)
20
 
21
  # Download the video
22
  info_dict = ydl.extract_info(url, download=True)
23
- audio_file_name = "audio_downloaded.{}".format(info_dict["ext"])
 
 
 
24
  audio_file= open(audio_file_name, "rb")
25
- transcript = openai.Audio.transcribe("whisper-1", audio_file)
 
 
 
26
  output = openai.ChatCompletion.create(
27
  model="gpt-3.5-turbo",
28
  messages=[
 
10
  ydl_opts = {
11
  'format': 'bestaudio/best',
12
  'outtmpl': 'audio_downloaded.%(ext)s',
 
13
  'no_continue': True,
14
  }
15
 
 
16
  # Create a youtube-dl object
17
  ydl = yt_dlp.YoutubeDL(ydl_opts)
18
 
19
  # Download the video
20
  info_dict = ydl.extract_info(url, download=True)
21
+ if info_dict is not None:
22
+ audio_file_name = "audio_downloaded.{}".format(info_dict["ext"])
23
+ else:
24
+ return "下载音频发生错误,请确认链接再试一次。", "Error downloading the audio. Check the URL and try again."
25
  audio_file= open(audio_file_name, "rb")
26
+ try:
27
+ transcript = openai.Audio.transcribe("whisper-1", audio_file)
28
+ except:
29
+ return "视频过大(超过25mb)了,无法处理。", "The audio file is too big (25mb)."
30
  output = openai.ChatCompletion.create(
31
  model="gpt-3.5-turbo",
32
  messages=[