mzltest commited on
Commit
9434a62
·
1 Parent(s): be15877

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -57,16 +57,21 @@ class YukieGradio:
57
  self.outVcText, self.outAudio, self.f0_image],api_name="go")
58
 
59
  def download_audio(url):
60
- # 发送请求
61
  response = requests.get(url)
62
- # 将响应内容读入内存
63
  audio_bytes = BytesIO(response.content)
64
- # 使用numpy将音频数据转为int16类型数组
65
- audio_data = np.frombuffer(audio_bytes.read(), dtype=np.int16)
66
- # 获取音频采样率
67
- sample_rate = response.headers.get('Sample-Rate')
68
- # 返回Tuple(int, numpy.array)
69
- return int(sample_rate), audio_data
 
 
 
 
 
 
70
 
71
  def infer(inMic, inAudio, transform, slice_db, lm, sid, dev):
72
  if inAudio != None:
 
57
  self.outVcText, self.outAudio, self.f0_image],api_name="go")
58
 
59
  def download_audio(url):
60
+ # 下载音频数据
61
  response = requests.get(url)
 
62
  audio_bytes = BytesIO(response.content)
63
+
64
+ # 转换音频格式为wav
65
+ y, sr = librosa.load(audio_bytes, sr=None)
66
+ with BytesIO() as wav_bytes:
67
+ soundfile.write(wav_bytes, y, sr, format='wav')
68
+ wav_bytes.seek(0)
69
+
70
+ # 读取wav文件
71
+ data, sr = soundfile.read(wav_bytes)
72
+ # 转换数据类型为int16
73
+ data = np.asarray(data * 32767, dtype=np.int16)
74
+ return sr, data
75
 
76
  def infer(inMic, inAudio, transform, slice_db, lm, sid, dev):
77
  if inAudio != None: