summaryrefslogtreecommitdiff
path: root/src/wasp-audio.el
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-11-26 03:23:31 -0500
committerLLLL Colonq <llll@colonq>2024-11-26 03:23:31 -0500
commit0b95071fe628d91238549b062961e724088d3b8b (patch)
treeb4cf3ae960e0b52ed014ab4ba423fda1075e5d60 /src/wasp-audio.el
parent6e3c47b1ad746f0891592a97cc6ffb6e0280adbb (diff)
Update :4
Diffstat (limited to 'src/wasp-audio.el')
-rw-r--r--src/wasp-audio.el153
1 files changed, 55 insertions, 98 deletions
diff --git a/src/wasp-audio.el b/src/wasp-audio.el
index eab8eb36..580a3e7e 100644
--- a/src/wasp-audio.el
+++ b/src/wasp-audio.el
@@ -3,52 +3,33 @@
;;; Code:
(require 'wasp-utils)
+(require 'wasp-ai)
-(defcustom w/play-audio-process "wasp-play-audio"
+(defcustom w/audio-play-process "wasp-audio-play"
"Name of process for playing audio with mpv."
:type '(string)
:group 'wasp)
-(defcustom w/transcribe-process "wasp-transcribe"
+(defcustom w/audio-record-process "wasp-audio-record"
"Name of process for transcribing speech using the Whisper API."
:type '(string)
:group 'wasp)
-(defcustom w/transcribe-buffer " *wasp-transcribe*"
- "Name of buffer used to store transcription output."
- :type '(string)
- :group 'wasp)
-
-(defcustom w/transcribe-error-buffer " *wasp-transcribe-error*"
- "Name of buffer used to store transcription errors."
- :type '(string)
- :group 'wasp)
-
-(defcustom w/stream-transcribe-buffer " *wasp-fake-chat-transcribe*"
- "Name of buffer used to store stream transcription output."
- :type '(string)
- :group 'wasp)
-
-(defcustom w/stream-transcribe-error-buffer " *wasp-fake-chat-transcribe-error*"
- "Name of buffer used to store fake chat transcription errors."
- :type '(string)
- :group 'wasp)
-
-(defvar w/current-stream-transcribe-process nil)
+(defvar w/audio-record-process-current nil)
+(defvar w/audio-keep-recording t)
+(defvar w/audio-voice-commands nil)
(defvar w/last-stream-transcription "")
-(defvar w/stream-keep-transcribing t)
-(defvar w/stream-transcribe-voice-commands nil)
(defun w/tts (msg)
"Use TTS to say MSG."
(start-process "wasp-tts" nil "say" (w/tempfile "wasp-tts" msg)))
-(defun w/play-audio (clip &optional k volume)
+(defun w/audio-play (clip &optional k volume)
"Play CLIP using mpv.
Call K when done.
If VOLUME is specified, use it to adjust the volume (100 is default)."
(make-process
- :name w/play-audio-process
+ :name w/audio-play-process
:buffer nil
:command
(list
@@ -73,13 +54,13 @@ If VOLUME is specified, use it to adjust the volume (100 is default)."
"Pronounce USER's name in using mpv.
Call K when done.
If VOLUME is specified, use it :)."
- (w/play-audio (w/asset (s-concat "rats/users/" user ".wav")) k volume))
+ (w/audio-play (w/asset (s-concat "rats/users/" user ".wav")) k volume))
(defun w/multipart-audio-helper (user rest &optional uservol clipvol)
"Player all of the files in REST intercalated with saying USER's name.
Adjust volumes by USERVOL and CLIPVOL."
(when (car rest)
- (w/play-audio
+ (w/audio-play
(car rest)
(when (cdr rest)
(lambda ()
@@ -104,10 +85,10 @@ USER it's your birthday today."
'(w/audio-rats-rats-we-are-the-rats
w/audio-rambling-sub-thanks))
(thankers-unnamed
- '((lambda (_) (w/play-audio (w/asset "rats/sam.wav") nil 90))
- (lambda (_) (w/play-audio (w/asset "rats/tyumici.mp3") nil 150))
- (lambda (_) (w/play-audio (w/asset "rats/abuffseagull.flac") nil 150))
- (lambda (_) (w/play-audio (w/asset "rats/unrecorded.wav") nil 150))
+ '((lambda (_) (w/audio-play (w/asset "rats/sam.wav") nil 90))
+ (lambda (_) (w/audio-play (w/asset "rats/tyumici.mp3") nil 150))
+ (lambda (_) (w/audio-play (w/asset "rats/abuffseagull.flac") nil 150))
+ (lambda (_) (w/audio-play (w/asset "rats/unrecorded.wav") nil 150))
))
(thanker
(w/pick-random
@@ -117,79 +98,55 @@ USER it's your birthday today."
thankers-unnamed))))
(funcall thanker user)))
-(defvar-local w/transcribe-callback nil)
-(defun w/begin-transcribe (k)
- "Start recording audio to transcribe, passing the result to K."
- (let ((buf (generate-new-buffer w/transcribe-buffer)))
- (with-current-buffer buf
- (setq-local w/transcribe-callback k)
- (erase-buffer))
- (message "Transcribing...")
- (make-process
- :name w/transcribe-process
- :buffer buf
- :command (list "transcribe")
- :stderr (get-buffer-create w/transcribe-error-buffer)
- :sentinel
- (lambda (_ _)
- (with-current-buffer buf
- (funcall w/transcribe-callback (buffer-string)))))))
-(defun w/end-transcribe ()
- "Finish recording transcription audio."
- (interactive)
- (message "End of transcription")
- (start-process "pkill" nil "pkill" "parecord")
- nil)
-
-(defun w/handle-stream-transcribe ()
+(defun w/audio-record-start ()
"Start recording audio to transcribe."
- (unless w/current-stream-transcribe-process
- (with-current-buffer (get-buffer-create w/stream-transcribe-buffer)
- (erase-buffer))
- (setq
- w/current-stream-transcribe-process
- (make-process
- :name "fig-fake-chat-transcribe"
- :buffer (get-buffer-create w/stream-transcribe-buffer)
- :command (list "transcribe")
- :stderr (get-buffer-create w/stream-transcribe-error-buffer)
- :sentinel
- (lambda (_ _)
- (setq w/current-stream-transcribe-process nil)
- (with-current-buffer (get-buffer-create w/stream-transcribe-buffer)
- (w/daily-log (format "[VOICE]: %s" (buffer-string)))
- (setq w/last-stream-transcription (buffer-string))
- (--each w/stream-transcribe-voice-commands
- (when (s-contains? (car it) (s-downcase w/last-stream-transcription))
- (funcall (cdr it)))))
- (when w/stream-keep-transcribing
- (w/handle-stream-transcribe)))))))
-
-(defun w/handle-stream-end-transcribe ()
+ (let ((tmp (s-concat (make-temp-name "/tmp/wasp-record-audio") ".wav")))
+ (unless w/audio-record-process-current
+ (setq
+ w/audio-record-process-current
+ (make-process
+ :name w/audio-record-process
+ :buffer nil
+ :command (list "parecord" tmp)
+ :sentinel
+ (lambda (_ _)
+ (setq w/audio-record-process-current nil)
+ (w/ai-transcribe
+ tmp
+ (lambda (msg)
+ (w/daily-log (format "[VOICE]: %s" msg))
+ (setq w/last-stream-transcription msg)
+ (--each w/audio-voice-commands
+ (when (s-contains? (car it) (s-downcase msg))
+ (funcall (cdr it))))))
+ (when w/audio-keep-recording
+ (w/audio-record-start))))))))
+
+(defun w/audio-record-end ()
"Stop recording audio to transcribe."
- (when w/current-stream-transcribe-process
+ (when w/audio-record-process-current
(start-process "pkill" nil "pkill" "parecord")))
-(defvar w/stream-transcribe-timer nil)
-(defun w/run-stream-transcribe-timer ()
- "Run the fake chatter transcription timer."
- (when w/stream-transcribe-timer
- (cancel-timer w/stream-transcribe-timer))
- (w/handle-stream-end-transcribe)
+(defvar w/audio-record-end-timer nil)
+(defun w/run-audio-record-end-timer ()
+ "Run the audio recording timer."
+ (when w/audio-record-end-timer
+ (cancel-timer w/audio-record-end-timer))
+ (w/audio-record-end)
(setq
- w/stream-transcribe-timer
- (run-with-timer 10 nil #'w/run-stream-transcribe-timer)))
+ w/audio-record-end-timer
+ (run-with-timer 10 nil #'w/run-audio-record-end-timer)))
-(defun w/start-stream-transcribe ()
- "Start transcribing speech for fake chatters."
+(defun w/start-audio-record ()
+ "Start recording audio."
(interactive)
- (setq w/stream-keep-transcribing t)
- (w/handle-stream-transcribe))
-(defun w/stop-stream-transcribe ()
- "Stop transcribing speech for fake chatters."
+ (setq w/audio-keep-recording t)
+ (w/audio-record-start))
+(defun w/stop-audio-record ()
+ "Stop recording audio."
(interactive)
- (setq w/stream-keep-transcribing nil)
- (w/handle-stream-end-transcribe))
+ (setq w/audio-keep-recording nil)
+ (w/audio-record-end))
(provide 'wasp-audio)
;;; wasp-audio.el ends here