syntax = "proto3";
package eci;

service ECI {
  rpc Init(InitRequest) returns (InitReply);
  // Bidirectional session: client streams TTS commands; server streams audio/index events.
  rpc Tts(stream TtsRequest) returns (stream TtsEvent);

  // Control helpers
  rpc SetParam(SetParamRequest) returns (Empty);
  rpc SetVParam(SetVParamRequest) returns (Empty);
  rpc GetVParam(GetVParamRequest) returns (GetVParamReply);
  rpc CopyVoice(CopyVoiceRequest) returns (Empty);
  rpc Stop(Empty) returns (Empty);
}

message Empty {}

message InitRequest {
  string eci_path = 1;         // e.g. "eloquence/eci.dll" (relative or absolute)
  uint32 voice_lang_id = 2;    // default 65536 (ENU) if 0
}
message InitReply {
  bool ok = 1;
  string message = 2;
  uint32 sample_rate = 3;      // 11025
  uint32 channels = 4;         // 1
  uint32 sample_bits = 5;      // 16
}

// ---- Streaming requests ----
message TtsRequest {
  oneof payload {
    AddText add_text = 1;
    InsertIndex insert_index = 2;
    Synthesize synth = 3;
    Pause pause = 4;           // client-side audio pause usually; here for completeness
    Terminate terminate = 5;   // end session
  }
}
message AddText     { string text = 1; }
message InsertIndex { int32 index = 1; }
message Synthesize  {}
message Pause       { bool on = 1; }
message Terminate   {}

// ---- Streaming events ----
message TtsEvent {
  oneof event {
    Audio audio = 1;   // raw PCM LITTLE-ENDIAN, 16-bit mono @ 11025 Hz
    Index index = 2;   // value >=0 for markers, -1 for end-of-string
    Stopped stopped = 3;
    VParams vparams = 4; // optional cache refresh
  }
}
message Audio  { bytes pcm = 1; }
message Index  { int32 value = 1; }
message Stopped{ bool dummy = 1; }
message VParams{ map<uint32,int32> data = 1; }

// ---- Control RPCs ----
message SetParamRequest { uint32 param = 1; int32 value = 2; }
message SetVParamRequest { uint32 param = 1; int32 value = 2; bool temporary = 3; }
message GetVParamRequest { uint32 param = 1; }
message GetVParamReply { int32 value = 1; }
message CopyVoiceRequest { uint32 variant = 1; }