Spaces:
Runtime error
Runtime error
ASG Models
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,12 @@ from typing import Any, Callable, Optional, Tuple, Union,Iterator
|
|
| 11 |
import numpy as np
|
| 12 |
import torch.nn as nn # Import the missing module
|
| 13 |
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def _inference_forward_stream(
|
| 17 |
self,
|
|
@@ -139,7 +144,7 @@ def generate_audio_ai(text,name_model):
|
|
| 139 |
#torch.cuda.empty_cache()
|
| 140 |
with torch.no_grad():
|
| 141 |
for chunk in _inference_forward_stream(model,input_ids=inputs.input_ids,attention_mask=inputs.attention_mask,speaker_embeddings= speaker_embeddings,chunk_size=256):
|
| 142 |
-
yield 16000,chunk#.cpu().numpy().squeeze()#.astype(np.int16).tobytes()
|
| 143 |
|
| 144 |
# yield generate_audio(text_answer,name_model)
|
| 145 |
def remove_extra_spaces(text):
|
|
|
|
| 11 |
import numpy as np
|
| 12 |
import torch.nn as nn # Import the missing module
|
| 13 |
|
| 14 |
+
import noisereduce as nr
|
| 15 |
|
| 16 |
+
def remove_noise_nr(audio_data,sr=16000):
|
| 17 |
+
"""يزيل الضوضاء باستخدام مكتبة noisereduce."""
|
| 18 |
+
reduced_noise = nr.reduce_noise(y=audio_data, sr=sr)
|
| 19 |
+
return reduced_noise
|
| 20 |
|
| 21 |
def _inference_forward_stream(
|
| 22 |
self,
|
|
|
|
| 144 |
#torch.cuda.empty_cache()
|
| 145 |
with torch.no_grad():
|
| 146 |
for chunk in _inference_forward_stream(model,input_ids=inputs.input_ids,attention_mask=inputs.attention_mask,speaker_embeddings= speaker_embeddings,chunk_size=256):
|
| 147 |
+
yield 16000,remove_noise_nr(chunk)#.cpu().numpy().squeeze()#.astype(np.int16).tobytes()
|
| 148 |
|
| 149 |
# yield generate_audio(text_answer,name_model)
|
| 150 |
def remove_extra_spaces(text):
|