【问题标题】:How to retrieve data from google speech async如何从谷歌语音异步检索数据
【发布时间】:2019-05-14 22:25:14
【问题描述】:

我正在设置一个服务器,我需要使用 Google 语音 API 来将音频翻译成文本。 该服务器向 Google 的 API 发送一个 post 请求并检索操作的 NAME(ID)。然后我尝试使用 NAME(ID) 发出获取请求以检索数据,但出现 404 错误。

我已经尝试将 api.get('/v1p1beta1/operations/{NAME}') 与 Google 的 API KEY 一起使用,例如 api.get('/v1p1beta1/operations/{NAME}?key={ key}') 但后来我收到了一个错误的请求。 这段代码也有效,但停止了,我不知道为什么。

 const api = await axios.create({
    baseURL: 'https://speech.googleapis.com',
    crossDomain: true,
    responseType: 'json',
    headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': "Bearer <<TOKEN>>"
    },
    });
    // calling api
    api.get('/v1p1beta1/operations/{NAME}')
    .then(resp=>{
        console.log( resp);

    }).
    catch('error');
})

【问题讨论】:

    标签: google-speech-api get-request


    【解决方案1】:

    我发现了问题,当我从服务器返回 NAME(ID) 时,它被四舍五入,然后当我调用 GET 函数时,ID 不匹配。我所做的是对值进行字符串化,它解决了问题。

    return JSON.stringify(result.data.name);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 1970-01-01
      相关资源
      最近更新 更多