refactor: dynamically import vlc only if used
This commit is contained in:
parent
98b89b7dd1
commit
2c44ca026a
1 changed files with 4 additions and 2 deletions
6
tts.py
6
tts.py
|
@ -1,12 +1,13 @@
|
||||||
import os
|
import os
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
import warnings
|
import warnings
|
||||||
|
import importlib
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import argparse
|
import argparse
|
||||||
from kokoro import KPipeline
|
from kokoro import KPipeline
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
import vlc
|
# import vlc
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import pyperclip
|
import pyperclip
|
||||||
|
|
||||||
|
@ -84,11 +85,12 @@ def generate_audio(generator, name, voice, device):
|
||||||
return output_files
|
return output_files
|
||||||
|
|
||||||
def play_audio(output_files):
|
def play_audio(output_files):
|
||||||
|
vlc_module = importlib.import_module("vlc")
|
||||||
print("Now playing generated audio...")
|
print("Now playing generated audio...")
|
||||||
length = len(output_files)
|
length = len(output_files)
|
||||||
for i, output in enumerate(output_files):
|
for i, output in enumerate(output_files):
|
||||||
full_path = os.path.abspath(output)
|
full_path = os.path.abspath(output)
|
||||||
media = vlc.MediaPlayer(f"file://{full_path}")
|
media = vlc_module.MediaPlayer(f"file://{full_path}")
|
||||||
media.play()
|
media.play()
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
duration=media.get_length() / 1000
|
duration=media.get_length() / 1000
|
||||||
|
|
Loading…
Reference in a new issue