test-rtechs commited on
Commit
b3c44ff
1 Parent(s): 8d827df

Update soni_translate/utils.py

Browse files
Files changed (1) hide show
  1. soni_translate/utils.py +28 -5
soni_translate/utils.py CHANGED
@@ -3,6 +3,8 @@ from .logging_setup import logger
3
  from urllib.parse import urlparse
4
  from IPython.utils import capture
5
  import re
 
 
6
 
7
  VIDEO_EXTENSIONS = [
8
  ".mp4",
@@ -66,6 +68,31 @@ def run_command(command):
66
  raise Exception(errors.decode())
67
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def print_tree_directory(root_dir, indent=""):
70
  if not os.path.exists(root_dir):
71
  logger.error(f"{indent} Invalid directory or file: {root_dir}")
@@ -143,10 +170,6 @@ def manual_download(url, dst):
143
 
144
 
145
  def download_list(text_downloads):
146
-
147
- if os.environ.get("ZERO_GPU") == "TRUE":
148
- raise RuntimeError("This option is disabled in this demo.")
149
-
150
  try:
151
  urls = [elem.strip() for elem in text_downloads.split(",")]
152
  except Exception as error:
@@ -484,4 +507,4 @@ def rename_file(current_name, new_name):
484
  return dir_new_name_file
485
  else:
486
  logger.error(f"File '{current_name}' does not exist.")
487
- return None
 
3
  from urllib.parse import urlparse
4
  from IPython.utils import capture
5
  import re
6
+ import soundfile as sf
7
+ import numpy as np
8
 
9
  VIDEO_EXTENSIONS = [
10
  ".mp4",
 
68
  raise Exception(errors.decode())
69
 
70
 
71
+ def write_chunked(
72
+ file,
73
+ data,
74
+ samplerate,
75
+ subtype=None,
76
+ endian=None,
77
+ format=None,
78
+ closefd=True,
79
+ chunk_size=0x1000
80
+ ):
81
+
82
+ data = np.asarray(data)
83
+ if data.ndim == 1:
84
+ channels = 1
85
+ else:
86
+ channels = data.shape[1]
87
+ with sf.SoundFile(
88
+ file, 'w', samplerate, channels,
89
+ subtype, endian, format, closefd
90
+ ) as f:
91
+ num_chunks = (len(data) + chunk_size - 1) // chunk_size
92
+ for chunk in np.array_split(data, num_chunks, axis=0):
93
+ f.write(chunk)
94
+
95
+
96
  def print_tree_directory(root_dir, indent=""):
97
  if not os.path.exists(root_dir):
98
  logger.error(f"{indent} Invalid directory or file: {root_dir}")
 
170
 
171
 
172
  def download_list(text_downloads):
 
 
 
 
173
  try:
174
  urls = [elem.strip() for elem in text_downloads.split(",")]
175
  except Exception as error:
 
507
  return dir_new_name_file
508
  else:
509
  logger.error(f"File '{current_name}' does not exist.")
510
+ return None