1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-08-17 06:00:33 +03:00

feat: kick off ASR engine support for Apple Silicon

This commit is contained in:
louistiti 2024-06-12 00:31:47 +08:00
parent 04c3e88224
commit 582b2aa572
4 changed files with 21 additions and 10 deletions

2
.gitignore vendored
View File

@ -22,8 +22,6 @@ debug.log
.env
.last-skill-npm-install
leon.json
bridges/python/src/Pipfile.lock
tcp_server/src/Pipfile.lock
tcp_server/src/lib/tts/models/*.pth
tcp_server/src/lib/tts/models/**/*.bin
tcp_server/src/lib/tts/models/**/*.json

View File

@ -204,7 +204,7 @@ SPACY_MODELS.set('fr', {
}
}
const installPythonPackages = async () => {
LogHelper.info(`Installing Python packages from ${pipfilePath}.lock...`)
LogHelper.info(`Installing Python packages from ${pipfilePath}...`)
// Delete .venv directory to reset the development environment
if (hasDotVenv) {
@ -214,7 +214,7 @@ SPACY_MODELS.set('fr', {
}
try {
await command('pipenv install --verbose --site-packages', {
await command('pipenv install --verbose --skip-lock', {
shell: true,
stdio: 'inherit'
})

View File

@ -6,7 +6,7 @@ import numpy as np
from faster_whisper import WhisperModel
from ..constants import ASR_MODEL_PATH_FOR_GPU, ASR_MODEL_PATH_FOR_CPU
from ..utils import ThrottledCallback
from ..utils import ThrottledCallback, is_macos
class ASR:
@ -20,21 +20,21 @@ class ASR:
self.log('Loading model...')
if device == 'auto':
device = 'cpu'
if torch.cuda.is_available(): device = 'cuda'
else: self.log('GPU not available. CUDA is not installed?')
if torch.backends.mps.is_available(): device = 'mps'
if 'cuda' in device:
assert torch.cuda.is_available()
self.log(f'Device: {device}')
compute_type = "float16"
compute_type = 'float16'
if is_macos():
compute_type = 'int8_float32'
if device == 'cpu':
compute_type = "int8_float32"
compute_type = 'int8_float32'
self.compute_type = compute_type
@ -169,7 +169,7 @@ class ASR:
self.log("Recording...")
frames = []
while True:
data = self.stream.read(self.chunk)
data = self.stream.read(self.chunk, exception_on_overflow=False)
data_np = np.frombuffer(data, dtype=np.int16)
# Check if the audio data contains any non-finite values

View File

@ -1,4 +1,5 @@
import time
import sys
class ThrottledCallback:
@ -12,3 +13,15 @@ class ThrottledCallback:
if current_time - self.last_call > self.min_interval:
self.callback(*args, **kwargs)
self.last_call = current_time
def is_macos():
return sys.platform == 'darwin'
def is_windows():
return sys.platform == 'win32'
def is_linux():
return sys.platform == 'linux'