XiaomiAI.SDK 1.0.0.1

The project is support developer to easy convert Xaiomi AI server request and response json content.

Install-Package XiaomiAI.SDK -Version 1.0.0.1
dotnet add package XiaomiAI.SDK --version 1.0.0.1
<PackageReference Include="XiaomiAI.SDK" Version="1.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XiaomiAI.SDK --version 1.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Xiaomi-ai-skill-converter

Download

NuGet

Documents

自定义技能开发文档

If you aren't a Xiaomi AI developer, please visit the 水滴平台.

System requirement

XaiomiAI.SDK

  • RequestContent

    Convert json from Xiaomi AI server to object.

  • ResponseContent

    Convert object to response json to Xaimi AI server.

Example

[HttpPost]
public async Task<ResponseContent> Post([FromBody]string value)
{
    using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
    {
        // read json content
        string requestJson = await reader.ReadToEndAsync();
        // convert to RequestContent 
        var requestContent = JsonConvert.DeserializeObject<RequestContent>(requestJson);
        // identify request type to generate response content
        switch (requestContent.Request.Type)
        {
            case RequestType.Intent:
                string displayText = "是的,帮你朗读现在气象";
                return new ResponseContent
                {
                    IsSessionEnd = false,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = displayText
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = displayText
                        },
                        Directives = new List<IDirectiveData>
                        {
                            new AudioDirectiveData
                            {
                                AudioItem = new AudioItemData
                                {
                                    Stream = new StreamData
                                    {
                                        Url = "http://xxxxx.mp3"
                                    }
                                }
                            },
                            new TTSDirectiveData
                            {
                                TTSItem = new TTSItemData
                                {
                                    Text = displayText
                                }
                            }
                        }
                    }
                };
            case RequestType.End:
                string endTxt = "期待您再次使用";
                return new ResponseContent
                {
                    IsSessionEnd = true,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = endTxt
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = endTxt
                        },
                    }
                };
            default:
                // None, Wakeup
                string wakeupTxt = "請問您需要什么服務呢?";
                return new ResponseContent
                {
                    IsSessionEnd = false,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = wakeupTxt
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = wakeupTxt
                        }
                    }
                };
        }
    }
}

Enter develop mode of the Xiaomi AI Speaker

If the state of the custom skill is testing or during cerficiation process, you can test it on the Xiaomi AI Speaker.

Steps:

  1. 对音箱说:进入开发者模式

    --------------测试中-------------------

  2. 用你的技能 调用名称 进行测试,只有处于测试中或者审核中的技能都能够进行测试

  3. 想要退出请说:进入用户模式

Xiaomi-ai-skill-converter

Download

NuGet

Documents

自定义技能开发文档

If you aren't a Xiaomi AI developer, please visit the 水滴平台.

System requirement

XaiomiAI.SDK

  • RequestContent

    Convert json from Xiaomi AI server to object.

  • ResponseContent

    Convert object to response json to Xaimi AI server.

Example

[HttpPost]
public async Task<ResponseContent> Post([FromBody]string value)
{
    using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
    {
        // read json content
        string requestJson = await reader.ReadToEndAsync();
        // convert to RequestContent 
        var requestContent = JsonConvert.DeserializeObject<RequestContent>(requestJson);
        // identify request type to generate response content
        switch (requestContent.Request.Type)
        {
            case RequestType.Intent:
                string displayText = "是的,帮你朗读现在气象";
                return new ResponseContent
                {
                    IsSessionEnd = false,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = displayText
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = displayText
                        },
                        Directives = new List<IDirectiveData>
                        {
                            new AudioDirectiveData
                            {
                                AudioItem = new AudioItemData
                                {
                                    Stream = new StreamData
                                    {
                                        Url = "http://xxxxx.mp3"
                                    }
                                }
                            },
                            new TTSDirectiveData
                            {
                                TTSItem = new TTSItemData
                                {
                                    Text = displayText
                                }
                            }
                        }
                    }
                };
            case RequestType.End:
                string endTxt = "期待您再次使用";
                return new ResponseContent
                {
                    IsSessionEnd = true,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = endTxt
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = endTxt
                        },
                    }
                };
            default:
                // None, Wakeup
                string wakeupTxt = "請問您需要什么服務呢?";
                return new ResponseContent
                {
                    IsSessionEnd = false,
                    Response = new ResponseData
                    {
                        ToSpeak = new ToSpeakData
                        {
                            Type = ToSpeakType.TTS,
                            Text = wakeupTxt
                        },
                        ToDisplay = new PlainTextToDisplayData
                        {
                            Text = wakeupTxt
                        }
                    }
                };
        }
    }
}

Enter develop mode of the Xiaomi AI Speaker

If the state of the custom skill is testing or during cerficiation process, you can test it on the Xiaomi AI Speaker.

Steps:

  1. 对音箱说:进入开发者模式

    --------------测试中-------------------

  2. 用你的技能 调用名称 进行测试,只有处于测试中或者审核中的技能都能够进行测试

  3. 想要退出请说:进入用户模式

Release Notes

1.0.0.1: modify some json tag for new version of Xiaomi AI request/response.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0.1 103 5/5/2019
1.0.0 250 3/15/2018