mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Merge pull request #68 from denizsafak/apple
Add MPS GPU acceleratin on Silicon Mac
This commit is contained in:
+20
-3
@@ -23,6 +23,7 @@ import abogen.hf_tracker as hf_tracker
|
|||||||
import static_ffmpeg
|
import static_ffmpeg
|
||||||
import threading # for efficient waiting
|
import threading # for efficient waiting
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import platform
|
||||||
|
|
||||||
|
|
||||||
def get_sample_voice_text(lang_code):
|
def get_sample_voice_text(lang_code):
|
||||||
@@ -310,8 +311,15 @@ class ConversionThread(QThread):
|
|||||||
|
|
||||||
self.log_updated.emit("\nInitializing TTS pipeline...")
|
self.log_updated.emit("\nInitializing TTS pipeline...")
|
||||||
|
|
||||||
# Set device based on use_gpu setting
|
# Set device based on use_gpu setting and platform
|
||||||
device = "cuda" if self.use_gpu else "cpu"
|
if self.use_gpu:
|
||||||
|
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||||
|
device = "mps" # Use MPS for Apple Silicon
|
||||||
|
else:
|
||||||
|
device = "cuda" # Use CUDA for other platforms
|
||||||
|
else:
|
||||||
|
device = "cpu"
|
||||||
|
|
||||||
tts = self.KPipeline(
|
tts = self.KPipeline(
|
||||||
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
||||||
)
|
)
|
||||||
@@ -1319,7 +1327,16 @@ class VoicePreviewThread(QThread):
|
|||||||
|
|
||||||
# Generate the preview and save to cache
|
# Generate the preview and save to cache
|
||||||
try:
|
try:
|
||||||
device = "cuda" if self.use_gpu else "cpu"
|
|
||||||
|
# Set device based on use_gpu setting and platform
|
||||||
|
if self.use_gpu:
|
||||||
|
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||||
|
device = "mps" # Use MPS for Apple Silicon
|
||||||
|
else:
|
||||||
|
device = "cuda" # Use CUDA for other platforms
|
||||||
|
else:
|
||||||
|
device = "cpu"
|
||||||
|
|
||||||
tts = self.kpipeline_class(
|
tts = self.kpipeline_class(
|
||||||
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
||||||
)
|
)
|
||||||
|
|||||||
+15
-5
@@ -239,13 +239,23 @@ def calculate_text_length(text):
|
|||||||
def get_gpu_acceleration(enabled):
|
def get_gpu_acceleration(enabled):
|
||||||
try:
|
try:
|
||||||
import torch
|
import torch
|
||||||
from torch.cuda import is_available
|
from torch.cuda import is_available as cuda_available
|
||||||
|
|
||||||
if not enabled:
|
if not enabled:
|
||||||
return "CUDA GPU available but using CPU.", False
|
return "GPU available but using CPU.", False
|
||||||
if is_available():
|
|
||||||
|
# Check for Apple Silicon MPS
|
||||||
|
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||||
|
if torch.backends.mps.is_available():
|
||||||
|
return "MPS GPU available and enabled.", True
|
||||||
|
else:
|
||||||
|
return "MPS GPU not available on Apple Silicon. Using CPU.", False
|
||||||
|
|
||||||
|
# Check for CUDA
|
||||||
|
if cuda_available():
|
||||||
return "CUDA GPU available and enabled.", True
|
return "CUDA GPU available and enabled.", True
|
||||||
# Gather more diagnostic info if CUDA is not available
|
|
||||||
|
# Gather CUDA diagnostic info if not available
|
||||||
try:
|
try:
|
||||||
cuda_devices = torch.cuda.device_count()
|
cuda_devices = torch.cuda.device_count()
|
||||||
cuda_error = (
|
cuda_error = (
|
||||||
@@ -257,7 +267,7 @@ def get_gpu_acceleration(enabled):
|
|||||||
cuda_error = str(e)
|
cuda_error = str(e)
|
||||||
return f"CUDA GPU is not available. Using CPU. ({cuda_error})", False
|
return f"CUDA GPU is not available. Using CPU. ({cuda_error})", False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error checking CUDA GPU: {e}", False
|
return f"Error checking GPU: {e}", False
|
||||||
|
|
||||||
|
|
||||||
def prevent_sleep_start():
|
def prevent_sleep_start():
|
||||||
|
|||||||
Reference in New Issue
Block a user