Skip to content

Commit

Permalink
Updated GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
avnlearn committed Sep 11, 2024
1 parent 2dd56cf commit 0f05e57
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ temp/
temp
main.py
*.bak
curses/
curses/
output.wav
out.pdf
1 change: 1 addition & 0 deletions example/gui_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class VoiceRecorder(RecorderScene):
def construct(self):
self.set_audio_service(RecorderService(), cache_dir_delete=True)
# self.set_audio_service(RecorderService())

circle = Circle()
square = Square().shift(2 * RIGHT)
Expand Down
37 changes: 37 additions & 0 deletions example/gui_example_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from manim import *

from manim_recorder.voiceover_scene import RecorderScene
from manim_recorder.recorder.gui import RecorderService


class VoiceRecorder(RecorderScene, MovingCameraScene):
def construct(self):
self.set_audio_service(RecorderService(), cache_dir_delete=True)
# self.set_audio_service(RecorderService())

circle = Circle()
square = Square().shift(2 * RIGHT)
math = MathTex(r"x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a}")

with self.voiceover(mobject=math) as tracker:
self.play(Write(math), run_time=tracker.duration)

self.play(self.camera.frame.animate.shift(DOWN * 10))

self.play(Unwrite(math))

with self.voiceover(math) as tracker:
self.play(Write(math), run_time=tracker.duration)

self.play(Unwrite(math))

with self.voiceover(text="This circle is drawn as I speak.") as tracker:
self.play(Create(circle), run_time=tracker.duration)
self.say_to_wait()
with self.voiceover(text="Let's shift it to the left 2 units.") as tracker:
self.play(circle.animate.shift(2 * LEFT), run_time=tracker.duration)

with self.voiceover(text="Thank you for watching.") as tracker:
self.play(Uncreate(circle))

self.wait()
7 changes: 4 additions & 3 deletions manim_recorder/multimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import wave
import subprocess
import time
import logging
from pathlib import Path
import sox
import pyaudio
Expand Down Expand Up @@ -91,7 +92,7 @@ def set_device_index(self, device_index) -> None:
self.device_index = device_index
return True
except Exception as e:
print("Invalid device index. Please try again.", e)
logging.error("Invalid device index. Please try again. {}".format(e))
return False

def set_channels(self, channels: int = None) -> None:
Expand All @@ -104,7 +105,7 @@ def set_channels(self, channels: int = None) -> None:
).get("maxInputChannels")
return True
except Exception as e:
print("Invalid device index. Please try again.", e)
logging.error("Invalid device index. Please try again. {}".format(e))
return False

def get_device_count(self) -> int:
Expand Down Expand Up @@ -148,7 +149,7 @@ def _record(self) -> None:
with self.lock:
self.frames.append(data)
except Exception as e:
print("An error occurred during recording:", e)
logging.error("An error occurred during recording: {}".format(e))
finally:
stream.stop_stream()
stream.close()
Expand Down
9 changes: 6 additions & 3 deletions manim_recorder/recorder/gui/__gui__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(
def initUI(self):
"""Initializes the user interface components."""
self.setWindowTitle("Audio Recorder")
self.setGeometry(100, 100, 500, 400)
self.setGeometry(100, 100, 600, 400)
WindowCenter(self, onTop=True)

layout = QVBoxLayout()
Expand All @@ -109,6 +109,7 @@ def initUI(self):
self.message_label = create_label(
"Message", "color:orange; font-size: 15px", align="c", wordwrap=True
)
message_layout.addStretch(1)
message_layout.addWidget(self.message_label)
layout.addLayout(message_layout)

Expand Down Expand Up @@ -239,6 +240,7 @@ def initUI(self):
"p": self.__play,
"t": self.__pause,
"Ctrl+S": self.save_audio,
"a": self._next,
"Ctrl+Q": self.close,
},
)
Expand Down Expand Up @@ -379,16 +381,17 @@ def _next(self):
== QMessageBox.Yes
):
self.save_audio()
if self.communicator:
self.communicator.accept.emit(self.recorder_service.__str__())
self.pause_button.setDisabled(True)
self.play_button.setDisabled(True)
self.stop_button.setDisabled(True)
self.rec_button.setDisabled(True)
self.save_button.setDisabled(True)
self.accept_button.setDisabled(True)
self.audacity_button.setDisabled(True)
logging.info("Audio File : {}".format(self.recorder_service.__str__()))
self.status_bar.showMessage("Loading ...")
if self.communicator:
self.communicator.accept.emit(self.recorder_service.__str__())

def save_audio(self):
"""Saves the recorded audio to a file."""
Expand Down
11 changes: 8 additions & 3 deletions manim_recorder/recorder/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import sys
import logging
from manim_recorder.recorder.base import AudioService
from manim_recorder.recorder.gui.__gui__ import Recorder, QApplication, sys
from manim_recorder.helper import get_audio_basename
Expand All @@ -26,7 +27,7 @@ def __init__(
self.communicator = Communicate()
self.communicator.accept.connect(self.recorder_complated)
self.recorder = Recorder(communicator=self.communicator)
self.recorder.show()
# self.recorder.show()
self.loop = QEventLoop()

def generate_from_text(
Expand All @@ -51,11 +52,15 @@ def generate_from_text(
if cached_result is not None:
return cached_result

if not self.recorder.isVisible():
self.recorder.show()

audio_path = get_audio_basename() + ".wav" if path is None else path

self.communicator.recorder_data.emit(
str(Path(cache_dir) / audio_path), text, voice_id, str(mobject)
)

self.loop = QEventLoop()
self.communicator.accept.connect(self.loop.quit)
self.loop.exec()
Expand All @@ -65,7 +70,7 @@ def generate_from_text(
return json_dict

def recorder_complated(self, message):
print(message)
logging.info(f"Save Audio File : {message}")

def app_exec(self):
self.recorder.close()
Expand Down
1 change: 0 additions & 1 deletion manim_recorder/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ def get_remaining_duration(self, buff: float = 0.0) -> float:
"""
# result= max(self.end_t - self.scene.last_t, 0)
result = max(self.end_t - self.scene.renderer.time + buff, 0)
# print(result)
return result
3 changes: 2 additions & 1 deletion manim_recorder/voiceover_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import re
import os
import sys
from typing import override
from pathlib import Path
from math import ceil
from contextlib import contextmanager
Expand Down Expand Up @@ -192,6 +192,7 @@ def voiceover(
finally:
self.wait_for_voiceover()

@override
def render(self, preview: bool = False):
"""
Renders this Scene.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "manim-recorder"
version = "0.2.3"
version = "0.2.4"
description = "Manim plugin for recorder"
authors = ["AvN Learn <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 0f05e57

Please sign in to comment.