2017-07-10 4 views
0

Mein request.sh Code:Base64-Decodierung fehlgeschlagen für „ZKgdjfk ......... in Google Cloud Sprach-API

#!/bin/bash 

# Copyright 2017 Google Inc. 

# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 

#  http://www.apache.org/licenses/LICENSE-2.0 

# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 

# Create a request file with our JSON request in the current directory 
FILENAME="request-"`date +"%s".json` 
cat <<EOF > $FILENAME 
{ 
    "config": { 
    "encoding":"FLAC", 
    "sampleRateHertz":16000, 
    "profanityFilter": true, 
    "languageCode": "en-US", 
    "speechContexts": { 
     "phrases": [''] 
    }, 
    "maxAlternatives": 1 
    }, 
    "audio": { 
    "content": 
    } 
} 
EOF 

# Update the languageCode parameter if one was supplied 
if [ $# -eq 1 ] 
    then 
    sed -i 'audio.base64' -e "s/en-US/$1/g" $FILENAME 
fi 

# Record an audio file, base64 encode it, and update our request object 
read -p "Press enter when you're ready to record" rec 
if [ -z $rec ]; then 
    rec --channels=1 --bits=16 --rate=16000 audio.flac trim 0 3 
    echo \"`base64 audio.flac`\" > audio.base64 
    sed -i 'audio.base64' -e '/ "content":/r audio.base64' $FILENAME 
fi 
echo Request "file" $FILENAME created: 
head -7 $FILENAME # Don't print the entire file because there's a giant base64 string 
echo $'\t"Your base64 string..."\n\x00\x00}\n}' 

# Call the speech API (requires an API key) 
read -p $'\nPress enter when you\'re ready to call the Speech API' var 
if [ -z $var ]; 
    then 
    echo "Running the following curl command:" 
    echo "curl -s -X POST -H 'Content-Type: application/json' --data-binary @${FILENAME} https://speech.googleapis.com/v1/speech:recognize?key=API_KEY" 
    curl -s -X POST -H "Content-Type: application/json" --data-binary @${FILENAME} https://speech.googleapis.com/v1/speech:recognize?key=MY_API_KEY 
fi 

ich den Fehler bekommen

{ 
     "error": { 
     "code": 400, 
     "message": "Invalid value at 'audio.content' (TYPE_BYTES), Base64 decoding failed for \"ZkxhQwAAACAAA....\"", 

"status": "INVALID_ARGUMENT", 
     "details": [ 
      { 
      "@type": "type.googleapis.com/google.rpc.BadRequest", 
      "fieldViolations": [ 
       { 
       "field": "audio.content", 
       "description": "Invalid value at 'audio.content' (TYPE_BYTES), Base64 decoding failed for \"Zkxh... 

Wenn ich ausgeführt request.sh bash-Datei, die obigen Fehler steigen.

Wie kann ich diesen Fehler beheben? oder Hat jemand ein Problem wie ich?

Antwort

0

Sieht aus, als hättest du den Code von Sara Robinson auf Hakernoon auch ausprobiert.

Ich hatte das gleiche Problem und this post from ZodiacLeo123 hat mir geholfen.

Sie haben den Sport "-w" Flagge

base64 -w 0 audio.flac 

Dies entfernt zusätzliche neue Zeilen hinzuzufügen.

Verwandte Themen