Skip to content

Commit

Permalink
Add stop function
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoCaracciolo committed Oct 3, 2024
1 parent 4de91cd commit b7e6913
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions examples/gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ def __init__(self):
self.button_change_variant.connect("clicked", self.change_variant)
self.button_speak = Gtk.Button(label="Speak")
self.button_speak.connect("clicked", self.speak)

self.button_stop = Gtk.Button(label="Stop")
self.button_stop.connect("clicked", self.stop)
hbox_bottom.pack_start(self.button_change_style, True, True, 0)
hbox_bottom.pack_start(self.button_change_expression, True, True, 0)
hbox_bottom.pack_start(self.button_change_variant, True, True, 0)
hbox_bottom.pack_start(self.button_speak, True, True, 0)

hbox_bottom.pack_start(self.button_stop, True, True, 0)

# Load the model and the images
self.__load_model("models/kurisu/model.json")
Expand All @@ -99,6 +100,9 @@ def change_style(self, event):
style = self.cycle_dict_values(self.model.get_styles(), str(self.model.get_current_style()))
self.model.set_current_style(style)

def stop(self, event):
self.model.stop()

def change_expression(self, event):
expression = self.cycle_dict_values(self.model.get_expressions(), str(self.model.get_current_expression()))
self.model.set_current_expression(expression)
Expand Down
5 changes: 5 additions & 0 deletions src/livepng/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def __speak(self, wavfile: str, random_variant: bool = True, play_audio: bool =
stream.close()
p.terminate()
audio_thread.join()
self.__update_frame(self.get_current_image())
# Speaking finished
# Notify the threads and release the lock
self.__notify_speak_finish(wavfile)
Expand All @@ -356,6 +357,10 @@ def __update_images(self, frames: list[str], frame_rate:int = 10):
break
self.__update_frame(frame)
sleep(1/frame_rate)

def stop(self):
"""Stop the speak function"""
self.__request_interrupt = True

def calculate_frames_from_audio(self, wavfile: str, frame_rate:int=10):
"""Precalculate every frame for the model
Expand Down
8 changes: 2 additions & 6 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
setup(
name = 'livepng',
packages = ['livepng'],
version = '0.1.7',
version = '0.1.8',
license='GGPLv3',
description = 'LivePNG is a format to create avatars based on PNG images with lipsync support',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author = 'Francesco Caracciolo',
author_email = '[email protected]',
url = 'https://github.com/francescocaracciolo/livepng',
download_url = 'https://github.com/FrancescoCaracciolo/LivePNG/archive/refs/tags/0.1.7.tar.gz',
download_url = 'https://github.com/FrancescoCaracciolo/LivePNG/archive/refs/tags/0.1.8.tar.gz',
keywords = ['avatar', 'png', 'lipsync', 'livepng', 'anime'],
install_requires=[
'pydub',
Expand All @@ -23,10 +23,6 @@
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down

0 comments on commit b7e6913

Please sign in to comment.