feat: show loading bar while playing audio
This commit is contained in:
parent
5bae7cf1fe
commit
b6f5d4fe68
1 changed files with 22 additions and 13 deletions
35
main.py
35
main.py
|
@ -1,12 +1,21 @@
|
||||||
from kokoro import KPipeline
|
|
||||||
import soundfile as sf
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import vlc
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from kokoro import KPipeline
|
||||||
|
import soundfile as sf
|
||||||
|
import vlc
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
pipeline = KPipeline(lang_code='a', device='xpu')
|
|
||||||
|
# See voices: https://huggingface.co/hexgrad/Kokoro-82M/blob/main/VOICES.md
|
||||||
|
voices = {
|
||||||
|
'pro': 'af_heart',
|
||||||
|
'hot': 'af_bella',
|
||||||
|
'asmr':'af_nicole',
|
||||||
|
'brit': 'bf_emma'
|
||||||
|
}
|
||||||
|
pipeline = KPipeline(lang_code='a', device='xpu', repo_id='hexgrad/Kokoro-82M')
|
||||||
|
|
||||||
# filename argument
|
# filename argument
|
||||||
file_path = sys.argv[1]
|
file_path = sys.argv[1]
|
||||||
|
@ -16,25 +25,25 @@ name = '.'.join(file_name.split('.')[:-1])
|
||||||
|
|
||||||
file = open(file_path, "r")
|
file = open(file_path, "r")
|
||||||
text = file.read()
|
text = file.read()
|
||||||
generator = pipeline(text, voice='af_bella')
|
generator = pipeline(text, voice=voices['asmr'])
|
||||||
|
|
||||||
output_files = []
|
output_files = []
|
||||||
|
length = 0
|
||||||
|
|
||||||
for i, (gs, ps, audio) in enumerate(generator):
|
for i, (gs, ps, audio) in enumerate(generator):
|
||||||
# print(i, gs, ps)
|
|
||||||
output_file_name=f'outputs/{name}-{i}.wav'
|
output_file_name=f'outputs/{name}-{i}.wav'
|
||||||
os.makedirs(os.path.dirname(output_file_name), exist_ok=True)
|
os.makedirs(os.path.dirname(output_file_name), exist_ok=True)
|
||||||
print(f"Done generating audio: {output_file_name}")
|
|
||||||
sf.write(output_file_name, audio, 24000)
|
|
||||||
output_files.append(output_file_name)
|
output_files.append(output_file_name)
|
||||||
|
sf.write(output_file_name, audio, 24000)
|
||||||
|
print(u'\u2713', output_file_name)
|
||||||
|
length = length + 1
|
||||||
|
|
||||||
for output in output_files:
|
for i, output in enumerate(output_files):
|
||||||
full_path = os.path.abspath(output)
|
full_path = os.path.abspath(output)
|
||||||
print(f"Playing: {output}")
|
|
||||||
media = vlc.MediaPlayer(f"file://{full_path}")
|
media = vlc.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
|
||||||
print(f"duration: {duration}s")
|
description = f"\u25B6 {i+1}/{length} ({'{0:0>5.2f}'.format(duration)}s)"
|
||||||
#for i in tqdm(range(100)):
|
for i in tqdm(range(100), desc=description):
|
||||||
sleep(duration)
|
sleep(duration / 100)
|
||||||
|
|
Loading…
Reference in a new issue