uncloseai.com/languages/scheme/tts.scm

37 lines
1 KiB
Scheme

#!/usr/bin/env guile
!#
;;; Text-to-Speech Example in GNU Guile
(use-modules (web client)
(web response)
(ice-9 binary-ports)
(json))
(define base-url "https://speech.ai.unturf.com/v1/audio/speech")
(define output-file "speech.mp3")
(define payload
(scm->json-string
'((model . "tts-1")
(voice . "alloy")
(speed . 0.9)
(input . "I think so therefore, Today is a wonderful day to grow something people love!"))))
(display "Generating speech from TTS...\n\n")
(catch #t
(lambda ()
(call-with-values
(lambda ()
(http-post base-url
#:body payload
#:headers '((Content-Type . "application/json"))))
(lambda (response body)
;; Write binary response to file
(call-with-output-file output-file
(lambda (port)
(put-bytevector port body)))
(format #t "Speech saved to: ~a\n" output-file))))
(lambda (key . args)
(format #t "Error: ~a ~a\n" key args)))