zxsipola123456 commited on
Commit
3a50740
·
verified ·
1 Parent(s): 5d9d5dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -40,49 +40,49 @@ async def text_to_speech_edge(text, language_code):
40
  #out_wav = knn_vc.match(query_seq, matching_set, topk=4)
41
  #torchaudio.save('output.wav', out_wav[None], 16000)
42
  #return 'output.wav'
43
- # def voice_change(audio_in, audio_ref):
44
- # samplerate1, data1 = wavfile.read(audio_in)
45
- # samplerate2, data2 = wavfile.read(audio_ref)
46
-
47
- # with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_in, \
48
- # tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_ref:
49
- # audio_in_path = tmp_audio_in.name
50
- # audio_ref_path = tmp_audio_ref.name
51
- # write(audio_in_path, samplerate1, data1)
52
- # write(audio_ref_path, samplerate2, data2)
53
-
54
- # query_seq = knn_vc.get_features(audio_in_path)
55
- # matching_set = knn_vc.get_matching_set([audio_ref_path])
56
- # out_wav = knn_vc.match(query_seq, matching_set, topk=4)
57
- # output_path = 'output.wav'
58
- # torchaudio.save(output_path, out_wav[None], 16000)
59
- # return output_path
60
-
61
  def voice_change(audio_in, audio_ref):
62
  samplerate1, data1 = wavfile.read(audio_in)
63
  samplerate2, data2 = wavfile.read(audio_ref)
64
 
65
- # 强制匹配音频文件的长度
66
- max_length = max(data1.shape[0], data2.shape[0])
67
-
68
- if data1.shape[0] < max_length:
69
- data1 = np.pad(data1, (0, max_length - data1.shape[0]), mode='constant')
70
- if data2.shape[0] < max_length:
71
- data2 = np.pad(data2, (0, max_length - data2.shape[0]), mode='constant')
72
-
73
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_in, \
74
  tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_ref:
75
  audio_in_path = tmp_audio_in.name
76
  audio_ref_path = tmp_audio_ref.name
77
- wavfile.write(audio_in_path, samplerate1, data1)
78
- wavfile.write(audio_ref_path, samplerate2, data2)
79
 
80
  query_seq = knn_vc.get_features(audio_in_path)
81
  matching_set = knn_vc.get_matching_set([audio_ref_path])
82
  out_wav = knn_vc.match(query_seq, matching_set, topk=4)
83
  output_path = 'output.wav'
84
- torchaudio.save(output_path, torch.tensor(out_wav)[None], 16000)
85
  return output_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  # 文字转语音(OpenAI)
87
  def tts(text, model, voice, api_key):
88
  if len(text) > 300:
 
40
  #out_wav = knn_vc.match(query_seq, matching_set, topk=4)
41
  #torchaudio.save('output.wav', out_wav[None], 16000)
42
  #return 'output.wav'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  def voice_change(audio_in, audio_ref):
44
  samplerate1, data1 = wavfile.read(audio_in)
45
  samplerate2, data2 = wavfile.read(audio_ref)
46
 
 
 
 
 
 
 
 
 
47
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_in, \
48
  tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_ref:
49
  audio_in_path = tmp_audio_in.name
50
  audio_ref_path = tmp_audio_ref.name
51
+ write(audio_in_path, samplerate1, data1)
52
+ write(audio_ref_path, samplerate2, data2)
53
 
54
  query_seq = knn_vc.get_features(audio_in_path)
55
  matching_set = knn_vc.get_matching_set([audio_ref_path])
56
  out_wav = knn_vc.match(query_seq, matching_set, topk=4)
57
  output_path = 'output.wav'
58
+ torchaudio.save(output_path, out_wav[None], 16000)
59
  return output_path
60
+
61
+ # def voice_change(audio_in, audio_ref):
62
+ # samplerate1, data1 = wavfile.read(audio_in)
63
+ # samplerate2, data2 = wavfile.read(audio_ref)
64
+
65
+ # # 强制匹配音频文件的长度
66
+ # max_length = max(data1.shape[0], data2.shape[0])
67
+
68
+ # if data1.shape[0] < max_length:
69
+ # data1 = np.pad(data1, (0, max_length - data1.shape[0]), mode='constant')
70
+ # if data2.shape[0] < max_length:
71
+ # data2 = np.pad(data2, (0, max_length - data2.shape[0]), mode='constant')
72
+
73
+ # with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_in, \
74
+ # tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_ref:
75
+ # audio_in_path = tmp_audio_in.name
76
+ # audio_ref_path = tmp_audio_ref.name
77
+ # wavfile.write(audio_in_path, samplerate1, data1)
78
+ # wavfile.write(audio_ref_path, samplerate2, data2)
79
+
80
+ # query_seq = knn_vc.get_features(audio_in_path)
81
+ # matching_set = knn_vc.get_matching_set([audio_ref_path])
82
+ # out_wav = knn_vc.match(query_seq, matching_set, topk=4)
83
+ # output_path = 'output.wav'
84
+ # torchaudio.save(output_path, torch.tensor(out_wav)[None], 16000)
85
+ # return output_path
86
  # 文字转语音(OpenAI)
87
  def tts(text, model, voice, api_key):
88
  if len(text) > 300: