You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi中http/2下gRPC对接谷歌云语音无响应问题求助

问题描述

我目前使用Grijjy的TgoHttpClient(依赖nghttp2.dll的HTTP/2客户端组件),通过HTTP/2对接谷歌云语音服务的StreamingRecognize接口,但谷歌端无响应,TgoHttpClient的OnRecv事件也未触发。如果创建TgoHttpClient时不启用HTTP/2,所有功能均可正常工作,但无法实现音频与识别结果的实时流传输。

请问是否有人成功使用HTTP/2和nghttp2.dll实现谷歌云语音对接,或知晓相关示例(其他语言亦可)?

相关代码

const
  GOOGLE_CLOUD_SPEECH_STREAMING  = 'https://speech.googleapis.com/google.cloud.speech.v1.Speech/StreamingRecognize';

var
  Gc: TgoHttpClient;
  Ps: TBytesStream;
  b1,b2: TBytes;
  n1,n2: Integer;

begin
         Ps := TBytesStream.Create; 
    //将第一个参数改为False就能正常工作!
          Gc := TgoHttpClient.Create(True, False); 
        
          with Gc do
          try
            Authorization := 'Bearer ' +  MyGCPAuthenticator1.AccessToken;
            RequestHeaders.AddOrSet('content-type', 'application/grpc');
            RequestHeaders.AddOrSet('user-agent', 'grpc-delphi/0.1.0-dev');
        
            OnRecv := DataReceived;
        
    //流中包含gRPC格式的请求配置和音频数据
            Ps.Clear;
            Ps.Write([0] + BytesOf(@n1, SizeOf(n1)) + b1, 1 + SizeOf(n1) + Length(b1));
            Ps.Write([0] + BytesOf(@n2, SizeOf(n2)) + b2, 1 + SizeOf(n2) + Length(b2));
            Ps.Position := 0;
        
            RequestData := Ps.Bytes;
        
            if not Post(GOOGLE_CLOUD_SPEECH_STREAMING, b1) then
            begin
              raise Exception.Create(ResponseStatusCode.ToString);
            end;
          finally
            HttpClientManager.Release(Gc);
          end;
end;

内容的提问来源于stack exchange,提问作者Ronald Ruijs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 05:45:21