Reputation: 1
please teach me how to make Powershell automatically save its tts output to TEXT file, as I'm getting just a long string like this:
{ "audioContent": "//NExAAQ4oIMABhEuDRESizqE7uehfMY8A...........
I have to process more than 1400 files :( what to do? Also is there a way to upload text more than 5000 symbols long? Also is it possible to automatically create SSML from HTML?
I've made everything as described in this Document
Upvotes: 0
Views: 331
Reputation: 61148
I'm still not quite sure what you mean here.. Are you saying that you have a lot of text files that now have content { "audioContent": "//NExAAQ4oIMABhEuDRESizqE7uehfMY8A...........
and you need to replace that content with just the part between the curly brackets?
If that is the case, you can do
Get-ChildItem -Path 'ThePathToLookForTheFiles' -File | ForEach-Object {
$_ | Set-Content -Value (($_ | Get-Content -Raw) -replace '^\{\s*"audioContent":\s*"([^}]+)\}', '$1')
}
For any new textfile, change the code from here a bit by capturing the result from the Invoke-WebRequest
and saving the audioContent
property to text file:
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
$params = @{
Method = 'POST'
Headers = $headers
ContentType = "application/json; charset=utf-8"
InFile = 'request.json'
Uri = "https://texttospeech.googleapis.com/v1/text:synthesize"
}
$content = Invoke-WebRequest @params | Select-Object -Expand Content
# save the textfile with just the base64 string:
Set-Content -Path 'TheFullPathAndFileName' -Value $content.audioContent
Hope that helps
Upvotes: 1