// Copyright (c) Musharraf Omer
//
// Licensed under the MIT License

syntax = "proto3";

package sonata_grpc;

service sonata_grpc {

  // Return sonata version
  rpc GetSonataVersion(Empty) returns (Version) {}

  // Load a voice from directory
  rpc LoadVoice(VoicePath) returns (VoiceInfo) {}

  // Get voice information
  rpc GetVoiceInfo(VoiceIdentifier) returns (VoiceInfo) {}

  // Get synthesis options
  rpc GetSynthesisOptions(VoiceIdentifier) returns (SynthesisOptions) {}

  // Set synthesis options
  rpc SetSynthesisOptions(VoiceSynthesisOptions) returns (SynthesisOptions) {}

  // Synthesize utterance
  rpc SynthesizeUtterance(Utterance) returns (stream SynthesisResult) {}

  // Synthesize utterance in realtime
  rpc SynthesizeUtteranceRealtime(Utterance) returns (stream WaveSamples) {}
}

enum SynthesisMode {
  MODE_UNSPECIFIED = 0;
  MODE_LAZY = 1;
  MODE_PARALLEL = 2;
  MODE_BATCHED = 3;
}
enum Quality {
  QUALITY_UNSPECIFIED = 0;
  QUALITY_X_LOW = 1;
  QUALITY_LOW = 2;
  QUALITY_MEDIUM = 3;
  QUALITY_HIGH = 4;
}

message Empty {}

message Version {
    string version = 1;
}

message VoiceIdentifier {
    string voice_id = 1;
}

message VoiceInfo {
  string voice_id = 1;
  SynthesisOptions synth_options = 2;
  map<int64, string> speakers = 3;
  AudioInfo audio = 4;
  optional string language = 5;
  optional Quality quality = 6;
  optional bool supports_streaming_output = 7;
}

message VoicePath {
  string config_path = 1;
}

// Contains text and other synthesis parameters
message Utterance {
  string voice_id = 1;
  string text = 2;
  SpeechArgs speech_args = 3;
  SynthesisMode synthesis_mode = 4;
}

message SynthesisOptions {
  optional string speaker = 1;
  optional float length_scale = 2;
  optional float noise_scale = 3;
  optional float noise_w = 4;
}

message VoiceSynthesisOptions{
    string voice_id = 1;
    SynthesisOptions synthesis_options = 2;
}

// Audio output information
message AudioInfo {
  uint32 sample_rate = 1;
  uint32 num_channels = 2;
  uint32 sample_width = 3;
}

// Contains  wave bytes for a synthesized utterance 
message SynthesisResult {
  bytes wav_samples = 1;
  float rtf = 2;
}

message WaveSamples {
  bytes wav_samples = 1;
}

message SpeechArgs {
    optional uint32 rate =1;
    optional uint32 volume =2;
    optional uint32 pitch =3;
    optional uint32 appended_silence_ms =4;
}
