Monkeytype qt/aqt/sound.py
This commit is contained in:
parent
eebf5d2a1d
commit
f8c22499cb
@ -87,7 +87,7 @@ class AVPlayer:
|
|||||||
# audio be stopped?
|
# audio be stopped?
|
||||||
interrupt_current_audio = True
|
interrupt_current_audio = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
self._enqueued: List[AVTag] = []
|
self._enqueued: List[AVTag] = []
|
||||||
self.current_player: Optional[Player] = None
|
self.current_player: Optional[Player] = None
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class AVPlayer:
|
|||||||
self._enqueued.insert(0, SoundOrVideoTag(filename=filename))
|
self._enqueued.insert(0, SoundOrVideoTag(filename=filename))
|
||||||
self._play_next_if_idle()
|
self._play_next_if_idle()
|
||||||
|
|
||||||
def toggle_pause(self):
|
def toggle_pause(self) -> None:
|
||||||
if self.current_player:
|
if self.current_player:
|
||||||
self.current_player.toggle_pause()
|
self.current_player.toggle_pause()
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ av_player = AVPlayer()
|
|||||||
|
|
||||||
# return modified command array that points to bundled command, and return
|
# return modified command array that points to bundled command, and return
|
||||||
# required environment
|
# required environment
|
||||||
def _packagedCmd(cmd) -> Tuple[Any, Dict[str, str]]:
|
def _packagedCmd(cmd: List[str]) -> Tuple[Any, Dict[str, str]]:
|
||||||
cmd = cmd[:]
|
cmd = cmd[:]
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
if "LD_LIBRARY_PATH" in env:
|
if "LD_LIBRARY_PATH" in env:
|
||||||
@ -205,7 +205,7 @@ def _packagedCmd(cmd) -> Tuple[Any, Dict[str, str]]:
|
|||||||
si = startup_info()
|
si = startup_info()
|
||||||
|
|
||||||
# osx throws interrupted system call errors frequently
|
# osx throws interrupted system call errors frequently
|
||||||
def retryWait(proc) -> Any:
|
def retryWait(proc: subprocess.Popen) -> int:
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
return proc.wait()
|
return proc.wait()
|
||||||
@ -227,7 +227,7 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
|
|||||||
args: List[str] = []
|
args: List[str] = []
|
||||||
env: Optional[Dict[str, str]] = None
|
env: Optional[Dict[str, str]] = None
|
||||||
|
|
||||||
def __init__(self, taskman: TaskManager):
|
def __init__(self, taskman: TaskManager) -> None:
|
||||||
self._taskman = taskman
|
self._taskman = taskman
|
||||||
self._terminate_flag = False
|
self._terminate_flag = False
|
||||||
self._process: Optional[subprocess.Popen] = None
|
self._process: Optional[subprocess.Popen] = None
|
||||||
@ -238,7 +238,7 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
|
|||||||
lambda: self._play(tag), lambda res: self._on_done(res, on_done)
|
lambda: self._play(tag), lambda res: self._on_done(res, on_done)
|
||||||
)
|
)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self) -> None:
|
||||||
self._terminate_flag = True
|
self._terminate_flag = True
|
||||||
# block until stopped
|
# block until stopped
|
||||||
t = time.time()
|
t = time.time()
|
||||||
@ -252,7 +252,7 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
|
|||||||
)
|
)
|
||||||
self._wait_for_termination(tag)
|
self._wait_for_termination(tag)
|
||||||
|
|
||||||
def _wait_for_termination(self, tag: AVTag):
|
def _wait_for_termination(self, tag: AVTag) -> None:
|
||||||
self._taskman.run_on_main(
|
self._taskman.run_on_main(
|
||||||
lambda: gui_hooks.av_player_did_begin_playing(self, tag)
|
lambda: gui_hooks.av_player_did_begin_playing(self, tag)
|
||||||
)
|
)
|
||||||
@ -359,7 +359,7 @@ class MpvManager(MPV, SoundOrVideoPlayer):
|
|||||||
def toggle_pause(self) -> None:
|
def toggle_pause(self) -> None:
|
||||||
self.set_property("pause", not self.get_property("pause"))
|
self.set_property("pause", not self.get_property("pause"))
|
||||||
|
|
||||||
def seek_relative(self, secs) -> None:
|
def seek_relative(self, secs: int) -> None:
|
||||||
self.command("seek", secs, "relative")
|
self.command("seek", secs, "relative")
|
||||||
|
|
||||||
def on_idle(self) -> None:
|
def on_idle(self) -> None:
|
||||||
@ -401,7 +401,7 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
|
|||||||
)
|
)
|
||||||
self._wait_for_termination(tag)
|
self._wait_for_termination(tag)
|
||||||
|
|
||||||
def command(self, *args) -> None:
|
def command(self, *args: Any) -> None:
|
||||||
"""Send a command over the slave interface.
|
"""Send a command over the slave interface.
|
||||||
|
|
||||||
The trailing newline is automatically added."""
|
The trailing newline is automatically added."""
|
||||||
@ -412,7 +412,7 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
|
|||||||
def seek_relative(self, secs: int) -> None:
|
def seek_relative(self, secs: int) -> None:
|
||||||
self.command("seek", secs, 0)
|
self.command("seek", secs, 0)
|
||||||
|
|
||||||
def toggle_pause(self):
|
def toggle_pause(self) -> None:
|
||||||
self.command("pause")
|
self.command("pause")
|
||||||
|
|
||||||
|
|
||||||
@ -458,12 +458,12 @@ class _Recorder:
|
|||||||
|
|
||||||
|
|
||||||
class PyAudioThreadedRecorder(threading.Thread):
|
class PyAudioThreadedRecorder(threading.Thread):
|
||||||
def __init__(self, startupDelay) -> None:
|
def __init__(self, startupDelay: float) -> None:
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.startupDelay = startupDelay
|
self.startupDelay = startupDelay
|
||||||
self.finish = False
|
self.finish = False
|
||||||
|
|
||||||
def run(self) -> Any:
|
def run(self) -> None:
|
||||||
chunk = 1024
|
chunk = 1024
|
||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ class PyAudioRecorder(_Recorder):
|
|||||||
# discard first 250ms which may have pops/cracks
|
# discard first 250ms which may have pops/cracks
|
||||||
startupDelay = 0.25
|
startupDelay = 0.25
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
for t in recFiles + [processingSrc, processingDst]:
|
for t in recFiles + [processingSrc, processingDst]:
|
||||||
try:
|
try:
|
||||||
os.unlink(t)
|
os.unlink(t)
|
||||||
@ -507,15 +507,15 @@ class PyAudioRecorder(_Recorder):
|
|||||||
pass
|
pass
|
||||||
self.encode = False
|
self.encode = False
|
||||||
|
|
||||||
def start(self):
|
def start(self) -> None:
|
||||||
self.thread = PyAudioThreadedRecorder(startupDelay=self.startupDelay)
|
self.thread = PyAudioThreadedRecorder(startupDelay=self.startupDelay)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self) -> None:
|
||||||
self.thread.finish = True
|
self.thread.finish = True
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
|
|
||||||
def file(self):
|
def file(self) -> str:
|
||||||
if self.encode:
|
if self.encode:
|
||||||
tgt = "rec%d.mp3" % time.time()
|
tgt = "rec%d.mp3" % time.time()
|
||||||
os.rename(processingDst, tgt)
|
os.rename(processingDst, tgt)
|
||||||
@ -530,7 +530,7 @@ Recorder = PyAudioRecorder
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
def getAudio(parent, encode=True):
|
def getAudio(parent: QWidget, encode: bool = True) -> Optional[str]:
|
||||||
"Record and return filename"
|
"Record and return filename"
|
||||||
# record first
|
# record first
|
||||||
r = Recorder()
|
r = Recorder()
|
||||||
@ -547,16 +547,16 @@ def getAudio(parent, encode=True):
|
|||||||
t = time.time()
|
t = time.time()
|
||||||
r.start()
|
r.start()
|
||||||
time.sleep(r.startupDelay)
|
time.sleep(r.startupDelay)
|
||||||
QApplication.instance().processEvents()
|
QApplication.instance().processEvents() # type: ignore
|
||||||
while not mb.clickedButton():
|
while not mb.clickedButton():
|
||||||
txt = _("Recording...<br>Time: %0.1f")
|
txt = _("Recording...<br>Time: %0.1f")
|
||||||
mb.setText(txt % (time.time() - t))
|
mb.setText(txt % (time.time() - t))
|
||||||
mb.show()
|
mb.show()
|
||||||
QApplication.instance().processEvents()
|
QApplication.instance().processEvents() # type: ignore
|
||||||
if mb.clickedButton() == mb.escapeButton():
|
if mb.clickedButton() == mb.escapeButton():
|
||||||
r.stop()
|
r.stop()
|
||||||
r.cleanup()
|
r.cleanup()
|
||||||
return
|
return None
|
||||||
saveGeom(mb, "audioRecorder")
|
saveGeom(mb, "audioRecorder")
|
||||||
# ensure at least a second captured
|
# ensure at least a second captured
|
||||||
while time.time() - t < 1:
|
while time.time() - t < 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user