您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:多设备对话Quickstart: Multi-device Conversation

本快速入门将介绍如何使用 Speech SDK 创建支持翻译的新的多设备对话,以及如何加入现有对话。In this quickstart, you'll learn how to use the Speech SDK to create a new multi-device conversation with translation support, as well as join an existing conversation.

可以在 GitHub 上查看或下载所有语音 SDK C# 示例You can view or download all Speech SDK C# Samples on GitHub.

先决条件Prerequisites

在开始之前,请务必:Before you get started, make sure to:

添加示例代码Add sample code

  1. 打开 Program.cs 并将其中的所有代码替换为以下代码:Open Program.cs, and replace all code in it with the following code:

    using Microsoft.CognitiveServices.Speech;
    using Microsoft.CognitiveServices.Speech.Audio;
    using Microsoft.CognitiveServices.Speech.Transcription;
    using System;
    using System.Threading.Tasks;
    
    namespace HelloWorld
    {
        class Program
        {
            static async Task Main(string[] args)
            {
                await CreateConversationAsync();
            }
    
            static async Task CreateConversationAsync()
            {
                // Replace these values with the details of your Cognitive Speech subscription
                string subscriptionKey = "YourSubscriptionKey";
    
                // Replace below with your region identifier from here: https://aka.ms/speech/sdkregion
                string region = "YourServiceRegion";
    
                // Sets source and target languages.
                // Replace with the languages of your choice, from list found here: https://aka.ms/speech/sttt-languages
                string fromLanguage = "en-US";
                string toLanguage = "de";
    
                // Set this to the display name you want for the conversation host
                string displayName = "The host";
    
                // Create the task completion source that will be used to wait until the user presses Ctrl + C
                var completionSource = new TaskCompletionSource<bool>();
    
                // Register to listen for Ctrl + C
                Console.CancelKeyPress += (s, e) =>
                {
                    completionSource.TrySetResult(true);
                    e.Cancel = true; // don't terminate the current process
                };
    
                // Create an instance of the speech translation config
                var config = SpeechTranslationConfig.FromSubscription(subscriptionKey, region);
                config.SpeechRecognitionLanguage = fromLanguage;
                config.AddTargetLanguage(toLanguage);
    
                // Create the conversation
                using (var conversation = await Conversation.CreateConversationAsync(config).ConfigureAwait(false))
                {
                    // Start the conversation so the host user and others can join
                    await conversation.StartConversationAsync().ConfigureAwait(false);
    
                    // Get the conversation ID. It will be up to your scenario to determine how this is shared with other participants.
                    string conversationId = conversation.ConversationId;
                    Console.WriteLine($"Created '{conversationId}' conversation");
    
                    // At this point, you can use the conversation object to manage the conversation. 
                    // For example, to mute everyone else in the room you can call this method:
                    await conversation.MuteAllParticipantsAsync().ConfigureAwait(false);
    
                    // Configure which audio source you want to use. If you are using a text only language, you 
                    // can use the other overload of the constructor that takes no arguments
                    var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
                    using (var conversationTranslator = new ConversationTranslator(audioConfig))
                    {
                        // You should connect all the event handlers you need at this point
                        conversationTranslator.SessionStarted += (s, e) =>
                        {
                            Console.WriteLine($"Session started: {e.SessionId}");
                        };
                        conversationTranslator.SessionStopped += (s, e) =>
                        {
                            Console.WriteLine($"Session stopped: {e.SessionId}");
                        };
                        conversationTranslator.Canceled += (s, e) =>
                        {
                            switch (e.Reason)
                            {
                                case CancellationReason.EndOfStream:
                                    Console.WriteLine($"End of audio reached");
                                    break;
    
                                case CancellationReason.Error:
                                    Console.WriteLine($"Canceled due to error. {e.ErrorCode}: {e.ErrorDetails}");
                                    break;
                            }
                        };
                        conversationTranslator.ConversationExpiration += (s, e) =>
                        {
                            Console.WriteLine($"Conversation will expire in {e.ExpirationTime.TotalMinutes} minutes");
                        };
                        conversationTranslator.ParticipantsChanged += (s, e) =>
                        {
                            Console.Write("The following participant(s) have ");
                            switch (e.Reason)
                            {
                                case ParticipantChangedReason.JoinedConversation:
                                    Console.Write("joined");
                                    break;
    
                                case ParticipantChangedReason.LeftConversation:
                                    Console.Write("left");
                                    break;
    
                                case ParticipantChangedReason.Updated:
                                    Console.Write("been updated");
                                    break;
                            }
    
                            Console.WriteLine(":");
    
                            foreach (var participant in e.Participants)
                            {
                                Console.WriteLine($"\t{participant.DisplayName}");
                            }
                        };
                        conversationTranslator.TextMessageReceived += (s, e) =>
                        {
                            Console.WriteLine($"Received an instant message from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                            foreach (var entry in e.Result.Translations)
                            {
                                Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                            }
                        };
                        conversationTranslator.Transcribed += (s, e) =>
                        {
                            Console.WriteLine($"Received a transcription from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                            foreach (var entry in e.Result.Translations)
                            {
                                Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                            }
                        };
                        conversationTranslator.Transcribing += (s, e) =>
                        {
                            Console.WriteLine($"Received a partial transcription from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                            foreach (var entry in e.Result.Translations)
                            {
                                Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                            }
                        };
    
                        // Enter the conversation to start receiving events
                        await conversationTranslator.JoinConversationAsync(conversation, displayName).ConfigureAwait(false);
    
                        // You can now send an instant message to all other participants in the room
                        await conversationTranslator.SendTextMessageAsync("The instant message to send").ConfigureAwait(false);
    
                        // If specified a speech-to-text language, you can start capturing audio
                        await conversationTranslator.StartTranscribingAsync().ConfigureAwait(false);
                        Console.WriteLine("Started transcribing. Press Ctrl + c to stop");
    
                        // At this point, you should start receiving transcriptions for what you are saying using the default microphone. Press Ctrl+c to stop audio capture
                        await completionSource.Task.ConfigureAwait(false);
    
                        // Stop audio capture
                        await conversationTranslator.StopTranscribingAsync().ConfigureAwait(false);
    
                        // Leave the conversation. After this you will no longer receive events
                        await conversationTranslator.LeaveConversationAsync().ConfigureAwait(false);
                    }
    
                    // End the conversation
                    await conversation.EndConversationAsync().ConfigureAwait(false);
    
                    // Delete the conversation. Any other participants that are still in the conversation will be removed
                    await conversation.DeleteConversationAsync().ConfigureAwait(false);
                }
            }
        }
    }
    
  2. 在同一文件中,将字符串 YourSubscriptionKey 替换为你的认知语音订阅密钥。In the same file, replace the string YourSubscriptionKey with your Cognitive Speech subscription key.

  3. 将字符串 YourServiceRegion 替换为与订阅关联的区域Replace the string YourServiceRegion with the region associated with your subscription.

  4. 在菜单栏中,选择“文件” > “全部保存”。From the menu bar, choose File > Save All.

构建并运行应用程序以创建新对话Build and run the application to create a new conversation

  1. 从菜单栏中,选择“构建” > “构建解决方案”以构建应用程序。From the menu bar, select Build > Build Solution to build the application. 现在,编译代码时应不会提示错误。The code should compile without errors now.

  2. 选择“调试” > “开始调试”(或按 F5)以启动 helloworld 应用程序。Choose Debug > Start Debugging (or press F5) to start the helloworld application.

  3. 看到 Started transcribing 消息出现后,你可以开始说话。Once you see the Started transcribing message appear, you can start speaking. 在你说话时,你会看到口述文本出现。You'll see the transcriptions appear as you speak.

    • 如果你与其他人分享对话代码并且他们加入了对话,则你还会看到他们的口述文本。If you share the conversation code with the others and they join the conversation, you'll see their transcriptions as well.
  4. 说话完毕后,按 Ctrl+C 停止音频捕获并终止对话。Once you're done speaking, press Ctrl+C to stop audio capture, and end the conversation.

构建并运行应用程序以加入现有对话Build and run the application to join an existing conversation

  1. 将以下函数复制并粘贴到 Program.cs 中:Copy and paste the following function into your Program.cs:

    static async Task JoinConversationAsync(string conversationId)
    {
        // Set this to the display name you want for the participant
        string displayName = "participant";
    
        // Set the speech to text, or text language you want to use
        string language = "en-US";
    
        // Create the task completion source that will be used to wait until the user presses Ctrl + c
        var completionSource = new TaskCompletionSource<bool>();
    
        // Register to listen for Ctrl+C
        Console.CancelKeyPress += (s, e) =>
        {
            completionSource.TrySetResult(true);
            e.Cancel = true; // don't terminate the current process
        };
    
        // As a participant, you don't need to specify any subscription key, or region. You can directly create
        // the conversation translator object
        var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
        using (var conversationTranslator = new ConversationTranslator(audioConfig))
        {
            // Register for any events you are interested here. For now let's just register for
            // transcription, and instant message events
            conversationTranslator.TextMessageReceived += (s, e) =>
            {
                Console.WriteLine($"Received an instant message from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                foreach (var entry in e.Result.Translations)
                {
                    Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                }
            };
            conversationTranslator.Transcribed += (s, e) =>
            {
                Console.WriteLine($"Received a transcription from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                foreach (var entry in e.Result.Translations)
                {
                    Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                }
            };
            conversationTranslator.Transcribing += (s, e) =>
            {
                Console.WriteLine($"Received a partial transcription from '{e.Result.ParticipantId}': '{e.Result.Text}'");
                foreach (var entry in e.Result.Translations)
                {
                    Console.WriteLine($"\tTranslated into '{entry.Key}': '{entry.Value}'");
                }
            };
    
            // To start receiving events, you will need to join the conversation
            await conversationTranslator.JoinConversationAsync(conversationId, displayName, language).ConfigureAwait(false);
    
            // You can now send an instant message
            await conversationTranslator.SendTextMessageAsync("Message from participant").ConfigureAwait(false);
    
            // Start capturing audio if you specified a speech-to-text language
            await conversationTranslator.StartTranscribingAsync().ConfigureAwait(false);
            Console.WriteLine("Started transcribing. Press Ctrl-C to stop");
    
            // At this point, you should start receiving transcriptions for what you are saying using
            // the default microphone. Press Ctrl+C to stop audio capture
            await completionSource.Task.ConfigureAwait(false);
    
            // Stop audio capture
            await conversationTranslator.StopTranscribingAsync().ConfigureAwait(false);
    
            // Leave the conversation. You will stop receiving events after this
            await conversationTranslator.LeaveConversationAsync().ConfigureAwait(false);
        }
    }
    
  2. 将你的 public static async Task Main(string[] args) 函数中的 CreateConversationAsync(); 替换为:Replace CreateConversationAsync(); in your public static async Task Main(string[] args) function with:

    // Set this to the conversation you want to join
    JoinConversationAsync("YourConversationId");
    
  1. 需要创建一个可加入的会话:You'll need to create a conversation that you can join:

    1. 启动浏览器并导航到:https://translator.microsoft.comLaunch your browser and navigate to: https://translator.microsoft.com.
    2. 单击“开始对话”。Click on "Start conversation".
    3. 使用任何可用选项登录。Sign in using any of the available options.
    4. 键入名称(例如,“The host”)。Type in a name (e.g. The host).
    5. 选择语言(例如,“英语”)。Select a language (e.g. English).
    6. 选择“输入” 按钮。Select the Enter button.
    7. 请注意页面顶部的对话代码。Note the conversation code at the top of the page.

    提示

    如果使用网页上的“复制”按钮,请确保删除开头的 translate.it/If you use the copy button on the web page, make sure you remove the translate.it/ at the start. 只需要 5 个字符的对话 ID(例如:“ABCDE”)。You only need the 5 character conversation ID (example: ABCDE).

  1. 返回到 Visual Studio,并将字符串 YourConversationId 替换为在上一步中创建的对话 ID。Go back to Visual Studio and replace the string YourConversationId with the conversation ID you created in the previous step.

  2. 从菜单栏中,选择“构建” > “构建解决方案”以构建应用程序。From the menu bar, select Build > Build Solution to build the application. 现在,编译代码时应不会提示错误。The code should compile without errors now.

  3. 选择“调试” > “开始调试”(或按 F5)以启动 helloworld 应用程序。Choose Debug > Start Debugging (or press F5) to start the helloworld application.

  4. 看到 Started transcribing 消息出现后,你可以开始说话。Once you see the Started transcribing message appear, you can start speaking. 在你说话时,你会看到口述文本出现。You'll see the transcriptions appear as you speak.

    • 如果返回到浏览器,则应当会看到在你说话时你的口述文本也出现在那里。If you go back to your browser, you should see your transcriptions appear there as you speak as well.
  5. 说话完毕后,按 Ctrl+C 停止音频捕获并终止对话。Once you're done speaking, press Ctrl+C to stop audio capture, and end the conversation.

  6. 返回到浏览器,并使用右上角的退出按钮退出对话。Go back to your browser and exit the conversation using the exit button in the upper right corner.

后续步骤Next Steps

可以在 GitHub 上查看或下载所有语音 SDK C++ 示例You can view or download all Speech SDK C++ Samples on GitHub.

先决条件Prerequisites

在开始之前,请务必:Before you get started, make sure to:

添加示例代码Add sample code

  1. 从 Visual Studio 中,打开源文件 helloworld.cppFrom Visual Studio, open the source file helloworld.cpp.

  2. 将所有代码替换为以下片段:Replace all the code with the following snippet:

    #include "pch.h"
    
    #define WIN32_LEAN_AND_MEAN
    #include <Windows.h>
    
    #include <iostream>
    #include <thread>
    #include <future>
    #include <string>
    #include <speechapi_cxx.h>
    
    using namespace std::chrono_literals;
    using namespace Microsoft::CognitiveServices::Speech;
    using namespace Microsoft::CognitiveServices::Speech::Audio;
    using namespace Microsoft::CognitiveServices::Speech::Transcription;
    
    // Create a promise we will set when the user presses Ctrl-C
    std::promise<bool> promise;
    // Create the future we will use to wait for the promise to be fulfilled
    std::future<bool> future = promise.get_future();
    
    void StartNewConversation()
    {
        // Set these
        std::string subscriptionKey("YourSubscriptionKey");
    
        // Replace below with your own region identifier from here: https://aka.ms/speech/sdkregion
        std::string region("YourServiceRegion");
    
        std::string speechLanguage("en-US");
    
        // Create the conversation object you'll need to manage the conversation
        auto speechConfig = SpeechConfig::FromSubscription(subscriptionKey, region);
        speechConfig->SetSpeechRecognitionLanguage(speechLanguage);
        auto conversation = Conversation::CreateConversationAsync(speechConfig).get();
    
        // Start the conversation so you and others can join
        conversation->StartConversationAsync().get();
    
        // Get the conversation ID. It will be up to your scenario to determine how this is shared with other participants.
        std::cout << "Created conversation: " << conversation->GetConversationId() << std::endl;
    
        // You can now call various commands to manage the room. For example:
        conversation->MuteAllParticipantsAsync().get();
    
        // Create the conversation translator you'll need to send audio, send IMs, and receive conversation events
        auto audioConfig = AudioConfig::FromDefaultMicrophoneInput();
        auto conversationTranslator = ConversationTranslator::FromConfig(audioConfig);
    
        // Add any event handlers
        conversationTranslator->SessionStarted += [](const SessionEventArgs& args)
        {
            std::cout << "Session started " << args.SessionId << std::endl;
        };
        conversationTranslator->SessionStopped += [](const SessionEventArgs& args)
        {
            std::cout << "Session stopped " << args.SessionId << std::endl;
        };
        conversationTranslator->Canceled += [](const ConversationTranslationCanceledEventArgs& args)
        {
            switch (args.Reason)
            {
                case CancellationReason::EndOfStream:
                    std::cout << "End of audio reached" << std::endl;
                    break;
    
                case CancellationReason::Error:
                    std::cout << "Canceled due to error. " << (long)args.ErrorCode << ": " << args.ErrorDetails << std::endl;
                    break;
            }
        };
        conversationTranslator->ConversationExpiration += [](const ConversationExpirationEventArgs& args)
        {
            std::cout << "Conversation will expire in " << args.ExpirationTime.count() << " minutes" << std::endl;
        };
        conversationTranslator->ParticipantsChanged += [](const ConversationParticipantsChangedEventArgs& args)
        {
            std::cout << "The following participant(s) have ";
            switch (args.Reason)
            {
                case ParticipantChangedReason::JoinedConversation:
                    std::cout << "joined";
                    break;
    
                case ParticipantChangedReason::LeftConversation:
                    std::cout << "left";
                    break;
    
                case ParticipantChangedReason::Updated:
                    std::cout << "been updated";
                    break;
            }
    
            std::cout << ":" << std::endl;
    
            for(std::shared_ptr<Participant> participant : args.Participants)
            {
                std::cout << "\t" << participant->DisplayName << std::endl;
            }
        };
        conversationTranslator->Transcribing += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received a partial transcription from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
        conversationTranslator->Transcribed += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received a transcription from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
        conversationTranslator->TextMessageReceived += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received an instant message from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
    
        // Join the conversation so you can start receiving events
        conversationTranslator->JoinConversationAsync(conversation, "Test Host").get();
    
        // Send an instant message
        conversationTranslator->SendTextMessageAsync("This is a short test message").get();
    
        // Start sending audio
        conversationTranslator->StartTranscribingAsync().get();
        std::cout << "Started transcribing. Press Ctrl + C to stop" << std::endl;
        future.get(); // wait for Ctrl - C to be pressed
    
        // Stop audio capture
        conversationTranslator->StopTranscribingAsync().get();
    
        // Leave the conversation. You will stop receiving events
        conversationTranslator->LeaveConversationAsync().get();
    
        // Once you are done, remember to delete the conversation.
        conversation->EndConversationAsync().get(); // You will not be able to rejoin after this
        conversation->DeleteConversationAsync().get(); // All participants still in the room will be ejected
    }
    
    int main()
    {
        // Register a handler for the Ctrl - C callback
        SetConsoleCtrlHandler(
            [](DWORD dwCtrlType) -> BOOL
            {
                if (dwCtrlType == CTRL_C_EVENT)
                {
                    // Signal that the user has pressed ctrl + C
                    promise.set_value(true);
                    return TRUE;
                }
    
                return FALSE;
            },
            TRUE);
    
        StartNewConversation();
    }
    
  3. 在同一文件中,将字符串 YourSubscriptionKey 替换为你的订阅密钥。In the same file, replace the string YourSubscriptionKey with your subscription key.

  4. 将字符串 YourServiceRegion 替换为与订阅关联的区域Replace the string YourServiceRegion with the region associated with your subscription.

  5. 在菜单栏中,选择“文件” > “全部保存”。From the menu bar, choose File > Save All.

构建并运行应用程序以创建新对话Build and run the application to create a new conversation

  1. 从菜单栏中,选择“构建” > “构建解决方案”以构建应用程序。From the menu bar, select Build > Build Solution to build the application. 现在,编译代码时应不会提示错误。The code should compile without errors now.

  2. 选择“调试” > “开始调试”(或按 F5)以启动 helloworld 应用程序。Choose Debug > Start Debugging (or press F5) to start the helloworld application.

  3. 看到 Started transcribing 消息出现后,你可以开始说话。Once you see the Started transcribing message appear, you can start speaking. 在你说话时,你会看到口述文本出现。You'll see the transcriptions appear as you speak

    • 如果你与其他人分享对话代码并且他们加入了对话,则你还会看到他们的口述文本。If you share the conversation code with the others and they join the conversation, you'll see their transcriptions as well.
  4. 说话完毕后,按键盘上的 Ctrl+C 停止音频捕获。Once you're done speaking, press Ctrl+C on your keyboard to stop audio capture.

    备注

    你可能会在 Visual Studio 中看到有关异常的类似以下内容的消息:Exception thrown at 0x76EB90BF (KernelBase.dll) in helloworld.exe: 0x40010005: Control-C. 可以放心地忽略此消息。You may see a message from Visual Studio about an exception similar to: Exception thrown at 0x76EB90BF (KernelBase.dll) in helloworld.exe: 0x40010005: Control-C. You can safely ignore this.

    按 F5 以继续操作Press F5 to continue.

构建并运行应用程序以加入现有对话Build and run the application to join an existing conversation

  1. 将以下函数复制并粘贴到 helloworld.cpp,紧靠在 int main() 函数之前:Copy and paste the following function into your helloworld.cpp just before the int main() function:

    void JoinExistingConversation(const std::string& conversationId)
    {
        std::string speechLanguage("en-US");
    
        // You'll now need to create a ConversationTranslator to send audio, send IMs, and receive conversation events
        auto audioConfig = AudioConfig::FromDefaultMicrophoneInput();
        auto conversationTranslator = ConversationTranslator::FromConfig(audioConfig);
    
        // Attach event handlers here. For example:
        conversationTranslator->Transcribing += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received a partial transcription from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
        conversationTranslator->Transcribed += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received a transcription from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
        conversationTranslator->TextMessageReceived += [](const ConversationTranslationEventArgs& args)
        {
            std::cout << "Received an instant message from " << args.Result->ParticipantId << ": " << args.Result->Text << std::endl;
            for (const auto& entry : args.Result->Translations)
            {
                std::cout << "\t" << entry.first << ": " << entry.second << std::endl;
            }
        };
    
        // Join the conversation
        conversationTranslator->JoinConversationAsync(conversationId, "participant", speechLanguage).get();
    
        // Start sending audio
        conversationTranslator->StartTranscribingAsync().get();
        std::cout << "Started transcribing. Press Ctrl + C to stop" << std::endl;
        future.get(); // wait for Ctrl - C to be pressed
    
        // Stop audio capture
        conversationTranslator->StopTranscribingAsync().get();
    
        // Once you are done, leave the conversation
        conversationTranslator->LeaveConversationAsync().get();
    }
    
  2. 将你的 int main() 函数中的 StartNewConversation(); 替换为:Replace StartNewConversation(); in your int main() function with:

    // Set this to the conversation you want to join
    JoinExistingConversation("YourConversationId");
    
  1. 需要创建一个可加入的会话:You'll need to create a conversation that you can join:

    1. 启动浏览器并导航到:https://translator.microsoft.comLaunch your browser and navigate to: https://translator.microsoft.com.
    2. 单击“开始对话”。Click on "Start conversation".
    3. 使用任何可用选项登录。Sign in using any of the available options.
    4. 键入名称(例如,“The host”)。Type in a name (e.g. The host).
    5. 选择语言(例如,“英语”)。Select a language (e.g. English).
    6. 选择“输入” 按钮。Select the Enter button.
    7. 请注意页面顶部的对话代码。Note the conversation code at the top of the page.

    提示

    如果使用网页上的“复制”按钮,请确保删除开头的 translate.it/If you use the copy button on the web page, make sure you remove the translate.it/ at the start. 只需要 5 个字符的对话 ID(例如:“ABCDE”)。You only need the 5 character conversation ID (example: ABCDE).

  1. 返回到 Visual Studio,并将你的 int main() 函数中的 YourConversationId 替换为上一步中的对话 ID。Go back to Visual Studio and replace YourConversationId in your int main() function with the conversation ID from the previous step.

  2. 从菜单栏中,选择“构建” > “构建解决方案”以构建应用程序。From the menu bar, select Build > Build Solution to build the application. 编译代码时应不会出错。The code should compile without errors.

  3. 选择“调试” > “开始调试”(或按 F5)以启动 helloworld 应用程序。Choose Debug > Start Debugging (or press F5) to start the helloworld application.

  4. 看到 Started transcribing 消息出现后,你可以开始说话。Once you see the Started transcribing message appear, you can start speaking. 在你说话时,你会看到口述文本出现。You'll see the transcriptions appear as you speak.

    • 如果返回到浏览器,则应当会看到在你说话时你的口述文本也出现在那里。If you go back to your browser, you should see your transcriptions appear there as you speak as well.
  5. 说话完毕后,按 Ctrl+C 停止音频捕获并终止对话。Once you're done speaking, press Ctrl+C to stop audio capture, and end the conversation.

    备注

    你可能会在 Visual Studio 中看到有关异常的类似以下内容的消息:Exception thrown at 0x76EB90BF (KernelBase.dll) in helloworld.exe: 0x40010005: Control-C. 可以放心地忽略此消息。You may see a message from Visual Studio about an exception similar to: Exception thrown at 0x76EB90BF (KernelBase.dll) in helloworld.exe: 0x40010005: Control-C. You can safely ignore this.

    按 F5 以继续操作Press F5 to continue.

  6. 返回到浏览器,并使用右上角的退出按钮退出对话。Go back to your browser and exit the conversation using the exit button in the upper right corner.

后续步骤Next steps