linxiaolong01 commited on
Commit
4c5eb2b
·
1 Parent(s): 008aef9

Add some filev9

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -26,51 +26,51 @@ import utils
26
  limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
27
 
28
 
29
- def process_func(x, sampling_rate, embeddings):
30
- """
31
- Predict emotions or extract embeddings from raw audio signal
32
- :param x: np.ndarray
33
- :param sampling_rate:
34
- :param embeddings:
35
- :return: np.ndarray
36
- """
37
- # run through processor to normalize signal
38
- # always returns a batch, so we just get the first entry
39
- # then we put it on the device
40
- y = processor(x, sampling_rate=sampling_rate)
41
- y = y['input_values'][0]
42
- y = torch.from_numpy(y).to(device)
43
- # run through model
44
- with torch.no_grad():
45
- y = emotion_model(y)[0 if embeddings else 1]
46
- # convert to numpy
47
- y = y.detach().cpu().numpy()
48
- return y
49
-
50
- def audio_postprocess(self, y):
51
- """
52
- 修改gr的音频后处理函数
53
- :param self:
54
- :param y:
55
- :return:
56
- """
57
- if y is None:
58
- return None
59
-
60
- if gr_utils.validate_url(y):
61
- file = gr_processing_utils.download_to_file(y, dir=self.temp_dir)
62
- elif isinstance(y, tuple):
63
- sample_rate, data = y
64
- file = tempfile.NamedTemporaryFile(
65
- suffix=".wav", dir=self.temp_dir, delete=False
66
- )
67
- gr_processing_utils.audio_to_file(sample_rate, data, file.name)
68
- else:
69
- file = gr_processing_utils.create_tmp_copy_of_file(y, dir=self.temp_dir)
70
-
71
- return gr_processing_utils.encode_url_or_file_to_base64(file.name)
72
-
73
- gr.Audio.postprocess = audio_postprocess
74
 
75
  def get_text(text, hps, is_symbol):
76
  """
 
26
  limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
27
 
28
 
29
+ # def process_func(x, sampling_rate, embeddings):
30
+ # """
31
+ # Predict emotions or extract embeddings from raw audio signal
32
+ # :param x: np.ndarray
33
+ # :param sampling_rate:
34
+ # :param embeddings:
35
+ # :return: np.ndarray
36
+ # """
37
+ # # run through processor to normalize signal
38
+ # # always returns a batch, so we just get the first entry
39
+ # # then we put it on the device
40
+ # y = processor(x, sampling_rate=sampling_rate)
41
+ # y = y['input_values'][0]
42
+ # y = torch.from_numpy(y).to(device)
43
+ # # run through model
44
+ # with torch.no_grad():
45
+ # y = emotion_model(y)[0 if embeddings else 1]
46
+ # # convert to numpy
47
+ # y = y.detach().cpu().numpy()
48
+ # return y
49
+
50
+ # def audio_postprocess(self, y):
51
+ # """
52
+ # 修改gr的音频后处理函数
53
+ # :param self:
54
+ # :param y:
55
+ # :return:
56
+ # """
57
+ # if y is None:
58
+ # return None
59
+
60
+ # if gr_utils.validate_url(y):
61
+ # file = gr_processing_utils.download_to_file(y, dir=self.temp_dir)
62
+ # elif isinstance(y, tuple):
63
+ # sample_rate, data = y
64
+ # file = tempfile.NamedTemporaryFile(
65
+ # suffix=".wav", dir=self.temp_dir, delete=False
66
+ # )
67
+ # gr_processing_utils.audio_to_file(sample_rate, data, file.name)
68
+ # else:
69
+ # file = gr_processing_utils.create_tmp_copy_of_file(y, dir=self.temp_dir)
70
+
71
+ # return gr_processing_utils.encode_url_or_file_to_base64(file.name)
72
+
73
+ # gr.Audio.postprocess = audio_postprocess
74
 
75
  def get_text(text, hps, is_symbol):
76
  """