AceCentre / AACSpeakHelper

Copies the pasteboard. Translates to defined lang, Reads aloud and replaces pasteboard with translated text
https://docs.acecentre.org.uk/products/v/aac-speak-helper-tool/
MIT License
0 stars 1 forks source link

Support Kurdish TTS #5

Closed willwade closed 1 year ago

willwade commented 1 year ago

Kurdish TTS is available from https://tts.asosoft.com

UPDATE: See https://github.com/AceCentre/TranslateAndTTS/blob/main/KurdishTTS/kurdishTTS.py - This now needs to become an engine option in the code.

I can't see an API - but it looks like a POST request sending back a mp3 file

NB:

eg

$.post("[https://tts.kurdishspeech.com/"](https://tts.kurdishspeech.com/%22), {
                        t: txt,
                        l: $('#chkKuLatin').is(':checked'),
                        p: $('#chkPunct').is(':checked')
                    },
                    function(data) {
                        var path = `[https://tts.kurdishspeech.com/static/TTS/${data}.mp3`;](https://tts.kurdishspeech.com/static/TTS/$%7Bdata%7D.mp3%60;)
                        $('.loading').hide();
                        $('#results').show();
                        $('.audio').html(`<audio controls autoplay><source src="${path}" type="audio/mpeg"></audio>`);
                    }
                );

e.g.

curl -X POST -F 't=سڵاو' -F 'l=true' -F 'p=false' https://tts.kurdishspeech.com

response is a number: https://tts.kurdishspeech.com/static/TTS/number.mp3

So to do this we need to build a TTS wrapper to this service to use Kurdish TTS.

NB: above - it looks like punctuation and characters are checked. Would have to repeat those functions client side.

Here is a code sample. NOTE: NO CHECKING

import requests
from playsound import playsound
import os

# Code should santise text using - https://tts.kurdishspeech.com/static/js/Normalizer.js
# see https://stackoverflow.com/questions/16467479/normalizing-unicode

# Should be:
# - Less than 2000 characters
# - Remove any html chars. 
# - NormaliseUnicode  https://stackoverflow.com/questions/16467479/normalizing-unicode
#
# NB: for the most part this is fine in AAC use cases where people are typing in pure sorani only

if os.path.exists('snd.mp3'):
    os.remove('snd.mp3')

PastedText = 'سڵاو'
url = 'https://tts.kurdishspeech.com'
myobj = {'t': PastedText, 'l': 'true', 'p':'false' }
x = requests.post(url, data = myobj)
snd=requests.get('https://tts.kurdishspeech.com/static/TTS/'+x.text+'.mp3')
with open('snd.mp3', 'wb') as f:
    f.write(snd.content)
playsound('snd.mp3')