当前位置:网站首页>HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast

HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast

2022-06-25 17:36:00 Huawei mobile services

When users have the need for cross language communication or audio content translation , Applications need to be able to automatically detect voice content and then output it to the language users need .

HMS Core Machine learning services Provide simultaneous interpretation Ability , Simultaneous interpretation realizes real-time translation of real-time input long speech into text and speech of different languages , And real-time output of the original voice text 、 The translated text and the voice broadcast of the translated text .

In the live class , Conference applications , Simultaneous interpretation is particularly important . such as , In conference applications , It can output the speech content of the speaker of the ongoing meeting to the target language in real time , It is convenient for people in different languages to understand the meeting content in real time , Improve meeting efficiency . In live broadcast applications , It can output the spoken content of the anchor to the language required by the user in real time , And then broadcast in real time , Improve the viewing experience of users .

HMS Core Machine learning services Simultaneous interpretation capability not only supports continuous 5 Hours of real-time long voice input is converted to text , It also supports the translation between Chinese and English and the broadcasting of various timbres , Meet the needs of different scenarios in different types of applications .

DEMO Example

Development steps

Before development , You need to complete the necessary development preparations , At the same time, please make sure that your project has been configured with HMS Core SDK Of Maven Warehouse address , And completed the service of SDK Integrate .

SDK The sample code is as follows :

dependencies{
    //  Introducing simultaneous interpretation services SDK
implementation 'com.huawei.hms:ml-computer-si-sdk:3.5.0.312'
}
  1. Please refer to the instructions for using cloud authentication information , Set the authentication information of your application .
  1. Create a simultaneous interpreting recognizer , And set the configuration .
MLSimultaneousInterpretationConfig config = new 
MLSimultaneousInterpretationConfig.Factory()
                //  Set source language , At present, it supports Chinese and English 
.setSourceLanguage(MLSimultaneousInterpretationConstants.LAN_ZH_CN)
                //  Set the target language , At present, it supports Chinese and English 
                .setTargetLanguage(MLSimultaneousInterpretationConstants.LAN_EN_US)
                //  Set the identification type . Support original text + Translation text + Translation pronunciation 
                .setResultType(MLSimultaneousInterpretationConstants.RESULT_TYPE_TEXT_TRANSLATED_VOICE)
                //  Set the speaker , Supporting 、 British male and female voices 
                .setPerson(MLSimultaneousInterpretationConstants.EN_FEMALE_VOICE)
                .create();
 MLSimultaneousInterpretationRecognizer = MLSimultaneousInterpretationRecognizer.getInstance();
  1. Create voice recognition result listener callback .
//  Callback implementation MLSimultaneousInterpretationListener, Implement the methods in the interface .
    protected class SIRecognitionListener implements MLSimultaneousInterpretationListener {
        @Override
        public void onStartListening() {
            //  The recorder began to receive sound .
 }
        @Override
        public void onVoiceDataReceived(byte[] data) {
            //  Return to the user's original PCM Audio stream and audio energy , The interface does not run in the main thread , The returned result needs to be processed in the child thread .
        }
        @Override
        public void onRecognizingResults(Bundle partialResults) {
            //  from SIRecognitionListener Received text for continuous speech recognition .
            // RESULTS_RECOGNIZING: Original text ;RESULTS_TRANS_RECOGNIZING:tts Text ;RESULTS_SN: Original serial number ;RESULTS_TRANS_SN:tts Serial number 
        }
        @Override
        public void onResults(Bundle results) {
            //  from SIRecognitionListener Receive complete sentences 
            // RESULTS_RECOGNIZED: The original result ;RESULTS_TRANS_RECOGNIZED:tts result 
        }
        @Override
        public void onError(int error, String errorMessage) {
            //  Call the interface after identifying the error .
        }
        @Override
        public void onState(int state, Bundle params) {
            //  Notify the application that the status has changed .
        }
    }
  1. Bind the simultaneous interpreting identifier .
mlSimultaneousInterpretationRecognizer.setMLSimultaneousInterpretationListener(new SIRecognitionListener());
  1. call startRecognizing Start speech recognition .
//  Start identifying . 
 mlSimultaneousInterpretationRecognizer.startRecognizing(config);
  1. When the identification is complete , End identifying and releasing resources .
if (mlSimultaneousInterpretationRecognizer!= null) {
  mlSimultaneousInterpretationRecognizer.destroy();
  }

Learn more >>

visit Official website of Huawei developer Alliance
obtain Development guidance document
Huawei mobile service open source warehouse address :GitHubGitee

Pay attention to our , The first time to understand HMS Core Latest technical information ~

原网站

版权声明
本文为[Huawei mobile services]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251721191370.html