alexylem / jarvis

Jarvis.sh is a simple configurable multi-lang assistant.
http://openjarvis.com
MIT License
810 stars 197 forks source link

STT Bing Speech API fix #909

Closed Nomekrax closed 5 years ago

Nomekrax commented 5 years ago

Bonjour,

Suite aux différents changements qu'à subit l'api stt bing, je vous propose ce patch permettant de régler l'issue #272 afin que le module puisse être de nouveau utilisable.

Je proposerais sûrement d'autres amélioration du code mais pour le moment c'est fonctionnel.

J'attend vos retours :)

Oliv4945 commented 5 years ago

Super. Je n'avais pas eu le temps d'implémenter l'API pour les régions Azure. Je test & merge au plus vite, merci !

Oliv4945 commented 5 years ago

C'est mergé dans beta, merci beaucoup @Nomekrax ! J'a fait deux modifs mineures pour expliquer la région et l'ajouter dès le Wizard

juepi commented 4 years ago

Hello Folks,

No idea if this project is still maintained, but i assume there are still a bunch of people who use it (like me). As it seems that the "beta" branch is not available (at least doesn't work for me) and the "Bing vs. Azure" migration has obviously never been included into the master branch, i'd like to share with you my "stt_engines/bing/main.sh" file which works perfectly well with Azure Speech services:

#!/bin/bash
LANG="de-DE"
SERVER="westeurope.stt.speech.microsoft.com"
URL="https://${SERVER}/speech/recognition/conversation/cognitiveservices/v1?language=${LANG}"

_bing_transcribe () {
    local request="$URL"
    request+="&format=simple"
    request+="&profanity=removed" #with this we avoid the insult with <profanity> tags

    json=`curl "$request" \
    -H "Ocp-Apim-Subscription-Key: $bing_speech_api_key" \
    -H "Accept: application/json" \
    -H "Transfer-Encoding: chunked" \
    -H "Host: ${SERVER}" \
    -H "Content-Type: audio/wav; codec=audio/pcm; samplerate=16000" \
    -H "Expect: 100-continue" \
    --data-binary "@$audiofile" \
    --silent --fail`

    if (( $? )); then
        echo "ERROR: bing recognition curl failed"
        exit 1
    fi
    $verbose jv_debug "DEBUG: json=$json"
    local status=`echo $json | perl -lne 'print $1 if m{"RecognitionStatus":"([^"]*)"}'`
    if [ "$status" = "Success" ]; then
        echo $json | perl -lne 'print $1 if m{"DisplayText":"([^"]*)"}' > $forder
    fi
}

# Internal: Speech To Text function for Bing
# Return value: none
# Return code: 0 if success
bing_STT () {
    LISTEN $audiofile || return $?
    _bing_transcribe &
   jv_spinner $!
   return $? # return code of _bing_transcribe
}

Note: you will probably need to adopt LANG and SERVER according to your language and Azure Region. Also note that you don't need to create a token.. just use your speech service key.