Ziyi Lin commited on
Commit
8db09f4
·
1 Parent(s): 39f6373

Add macOS and Windows support with usage of prebuilt-lib

Browse files
Files changed (2) hide show
  1. include/ten_vad.py +51 -14
  2. setup.py +20 -3
include/ten_vad.py CHANGED
@@ -7,31 +7,68 @@
7
  from ctypes import c_int, c_int32, c_float, c_size_t, CDLL, c_void_p, POINTER
8
  import numpy as np
9
  import os
 
10
 
11
  class TenVad:
12
  def __init__(self, hop_size: int = 256, threshold: float = 0.5):
13
  self.hop_size = hop_size
14
  self.threshold = threshold
15
- if os.path.exists(
16
- os.path.join(
17
  os.path.dirname(os.path.relpath(__file__)),
18
- "../lib/Linux/x64/libten_vad.so",
19
  )
20
- ):
21
- self.vad_library = CDLL(
22
- os.path.join(
23
- os.path.dirname(os.path.relpath(__file__)),
24
- "../lib/Linux/x64/libten_vad.so",
 
25
  )
 
 
 
 
 
 
26
  )
27
- else:
28
- self.vad_library = CDLL(
29
- os.path.join(
30
- os.path.dirname(
31
- os.path.relpath(__file__)),
32
- "./ten_vad_library/libten_vad.so",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  )
 
 
 
 
 
34
  )
 
 
 
 
 
 
 
 
 
 
35
  self.vad_handler = c_void_p(0)
36
  self.out_probability = c_float()
37
  self.out_flags = c_int32()
 
7
  from ctypes import c_int, c_int32, c_float, c_size_t, CDLL, c_void_p, POINTER
8
  import numpy as np
9
  import os
10
+ import platform
11
 
12
  class TenVad:
13
  def __init__(self, hop_size: int = 256, threshold: float = 0.5):
14
  self.hop_size = hop_size
15
  self.threshold = threshold
16
+ if platform.system() == "Linux" and platform.machine() == "x86_64":
17
+ git_path = os.path.join(
18
  os.path.dirname(os.path.relpath(__file__)),
19
+ "../lib/Linux/x64/libten_vad.so"
20
  )
21
+ if os.path.exists(git_path):
22
+ self.vad_library = CDLL(git_path)
23
+ else:
24
+ pip_path = os.path.join(
25
+ os.path.dirname(os.path.relpath(__file__)),
26
+ "./ten_vad_library/libten_vad.so"
27
  )
28
+ self.vad_library = CDLL(pip_path)
29
+
30
+ elif platform.system() == "Darwin":
31
+ git_path = os.path.join(
32
+ os.path.dirname(os.path.relpath(__file__)),
33
+ "../lib/macOS/ten_vad.framework/Versions/A/ten_vad"
34
  )
35
+ if os.path.exists(git_path):
36
+ self.vad_library = CDLL(git_path)
37
+ else:
38
+ pip_path = os.path.join(
39
+ os.path.dirname(os.path.relpath(__file__)),
40
+ "./ten_vad_library/libten_vad"
41
+ )
42
+ self.vad_library = CDLL(pip_path)
43
+ elif platform.system().upper() == 'WINDOWS':
44
+ if platform.machine().upper() in ['X64', 'X86_64', 'AMD64']:
45
+ git_path = os.path.join(
46
+ os.path.dirname(os.path.realpath(__file__)),
47
+ "../lib/Windows/x64/ten_vad.dll"
48
+ )
49
+ if os.path.exists(git_path):
50
+ self.vad_library = CDLL(git_path)
51
+ else:
52
+ pip_path = os.path.join(
53
+ os.path.dirname(os.path.realpath(__file__)),
54
+ "./ten_vad_library/ten_vad.dll"
55
  )
56
+ self.vad_library = CDLL(pip_path)
57
+ else:
58
+ git_path = os.path.join(
59
+ os.path.dirname(os.path.realpath(__file__)),
60
+ "../lib/Windows/x86/ten_vad.dll"
61
  )
62
+ if os.path.exists(git_path):
63
+ self.vad_library = CDLL(git_path)
64
+ else:
65
+ pip_path = os.path.join(
66
+ os.path.dirname(os.path.realpath(__file__)),
67
+ "./ten_vad_library/ten_vad.dll"
68
+ )
69
+ self.vad_library = CDLL(pip_path)
70
+ else:
71
+ raise NotImplementedError(f"Unsupported platform: {platform.system()} {platform.machine()}")
72
  self.vad_handler = c_void_p(0)
73
  self.out_probability = c_float()
74
  self.out_flags = c_int32()
setup.py CHANGED
@@ -5,7 +5,7 @@
5
  # Refer to the "LICENSE" file in the root directory for more information.
6
  #
7
  from setuptools import setup
8
- import os, shutil
9
  from setuptools.command.install import install
10
 
11
  class custom_install_command(install):
@@ -13,8 +13,25 @@ class custom_install_command(install):
13
  install.run(self)
14
  target_dir = os.path.join(self.install_lib, "ten_vad_library")
15
  os.makedirs(target_dir, exist_ok=True)
16
- shutil.copy("lib/Linux/x64/libten_vad.so", target_dir)
17
- print(f"Files installed to: {target_dir}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  root_dir = os.path.dirname(os.path.abspath(__file__))
20
  shutil.copy(f"{root_dir}/include/ten_vad.py", f"{root_dir}/ten_vad.py")
 
5
  # Refer to the "LICENSE" file in the root directory for more information.
6
  #
7
  from setuptools import setup
8
+ import os, shutil, platform
9
  from setuptools.command.install import install
10
 
11
  class custom_install_command(install):
 
13
  install.run(self)
14
  target_dir = os.path.join(self.install_lib, "ten_vad_library")
15
  os.makedirs(target_dir, exist_ok=True)
16
+
17
+ if platform.system() == "Linux" and platform.machine() == "x86_64":
18
+ shutil.copy("lib/Linux/x64/libten_vad.so", target_dir)
19
+ print(f"Linux x64 library installed to: {target_dir}")
20
+ elif platform.system() == "Darwin":
21
+ shutil.copy("lib/macOS/ten_vad.framework/Versions/A/ten_vad",
22
+ os.path.join(target_dir, "libten_vad"))
23
+ print(f"macOS library installed to: {target_dir}")
24
+ elif platform.system().upper() == 'WINDOWS':
25
+ if platform.machine().upper() in ['X64', 'X86_64', 'AMD64']:
26
+ shutil.copy("lib/Windows/x64/ten_vad.dll",
27
+ os.path.join(target_dir, "ten_vad.dll"))
28
+ print(f"Windows x64 library installed to: {target_dir}")
29
+ else:
30
+ shutil.copy("lib/Windows/x86/ten_vad.dll",
31
+ os.path.join(target_dir, "ten_vad.dll"))
32
+ print(f"Windows x86 library installed to: {target_dir}")
33
+ else:
34
+ raise NotImplementedError(f"Unsupported platform: {platform.system()} {platform.machine()}")
35
 
36
  root_dir = os.path.dirname(os.path.abspath(__file__))
37
  shutil.copy(f"{root_dir}/include/ten_vad.py", f"{root_dir}/ten_vad.py")