Been a while since I’ve tried any TTS stuff, but todays aspirations again included “integrating” webthings like FreeSound.
I think gem management is still on the SP_wishlist, and tried the workaround mentioned to copy the installed freesound gem to vendors dir, but that didn’t work, but then I tried some web stuff in SP, then tried to sanitise and synthesise… and amazingly, it worked!
I’m hoping to take this to the next level and then get these into buffers for reuse and manipulation, and exploration into fx
and onset
Requirements
- The data is being fetched from an api, so you’ll need some internet, and an api key.
I think this first how to cited the nasa apis*
5 ways to make HTTP requests in Ruby | Twilio
and my first google result for a quotes api found this
Quotes API - API Ninjas (api-ninjas.com) - register and verify for free api
*there are many, and I didn’t even realise the APOD one I was using was returning pictures!
NASA Open APIs
- on windows using nircmd from nirsoft;
winget install wincmd
for ease I placed in my windows directory as the copy in my paths folder wasn’t being found by the system call
alternatively you could use some SAPI thing via Powershell- I looked for apis that return speech as wave files; nothing yet, but will look into this further
v0: test
system("nircmd speak text hello")
If anyone knows anyway to pipe an argument into system call please let me know!
As a workaround to this blocker we 1) write what we want to say to a file, then 2) speak from file
v1: inspirational quotes
txtfile = 'C:/temp/sp_nircmd_speak.txt'
require 'uri'
require 'net/http'
category = %w(art famous god history inspirational life love).choose
uri = URI('https://api.api-ninjas.com/v1/quotes?category='+category)
ninjakey = 'your-api-key-here'
params = { 'X-Api-Key': ninjakey}
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
#puts res.body if res.is_a?(Net::HTTPSuccess)
data = res.body #data needs sanitising
#quote indices
start_index = data.index('quote": "') + 'quote": "'.length
end_index = data.index('"', start_index) - 1 # quote ends with "
#puts start_index, end_index #debug
substring = data[start_index..end_index]
File.open(txtfile, "w") {|f| f.write(substring)} #1) write data to file
wait 0.5
`nircmd speak file C:/temp/sp_nircmd_speak.txt` #2) speak!
I tried wrapping up with a sufficiently long delay between calls, but eventually a timing error ended the fun, after wrapping the above up in a speak
method (optionally passing category as explicit)
use_sched_ahead_time 2 # I always need this for short sleeps like 1.0 / 16 @ 60bpm
live_loop :l1, delay: 2 do
tick
sample :bass_dnb_f if (spread 3, 16).look
sample :bd_808, amp: 1.8 if (spread 7, 16).look
cue :speak if (factor? look, 16*16)
sleep 1.0 / 16
end
live_loop :l2, sync: :speak do
# stop
# wait
speak
sync :speak
end
I recorded the performance but forgot SP isn’t currently speaking the sounds!
For that the speech needs writing to file, then playing… v2 coming up!