已比較的版本

索引鍵

  • 此行已新增。
  • 此行已移除。
  • 格式已變更。

...

  1. Define message formats in a .proto file.

    • Please refer to

      View file
      nameframes.proto
      of Davinci Voice Engine.

  2. Compile your .proto file to get the generated source code.

    • pre-compiled generated source code (ready-to-use)

  3. Include/import the generated source code with protocol buffer API to encode (serialize) and decode (deserialize) messages.

    • Example

      • Python

        程式碼區塊
        languagepy
        from protobuf import frames_pb2
        from google.protobuf.json_format import MessageToJson
        
        # Encode (Serialize)
        fake_audio_data = b'\x00\x01\x02\x03'
        frame = frames_pb2.Frame()
        frame.audio.audio = fake_audio_data
        frame.audio.sample_rate = 16000
        frame.audio.num_channels = 1
        serialized_bystring = frame.SerializeToString()
        
        # Decode (deserialize)
        frame = frames_pb2.Frame()
        frame.ParseFromString(serialized_bystring)
        json_frame = MessageToJson(frame)
        ## Check the type of frame.
        if frame.HasField('audio'):
            pass
        elif frame.HasField('text'):
            pass

...

  • Decoding:

    • Determine the frame type by inspecting the first byte, and the frame length by inspecting the following bytes. (Refer to the illustration below)

      • AudioRawFrame

        • The whole frame

          pb_series_audiorawframe.png
      • TextFrame

        • The whole frame

...

  • Encoding:

    • Must include the first few bytes indicating the frame type to the server.

      • AudioRawFrame

        • Bytestring starts from b'\x12'

      • TextFrame

        • Bytestring starts from b'\n'

...