DEV Community

HarmonyOS
HarmonyOS

Posted on

How to Use Huawei Core-Speech Kit for English and Japanese Text-to-Speech (TTS)

Read the original article:How to Use Huawei Core-Speech Kit for English and Japanese Text-to-Speech (TTS)

Think Huawei’s Core-Speech Kit only supports Chinese? Think again. Here’s how you can easily unlock high-quality English and Japanese text-to-speech — with just a few lines of code and zero hacks.

Introduction

Text-to-Speech (TTS) is a widely adopted technology in mobile and web development that converts written text into spoken voice. It’s used in everything from virtual assistants to e-learning apps, accessibility tools, and more. While Huawei’s Core-Speech Kit is officially documented to support only Chinese, developers can actually implement TTS functionality for English and Japanese as well — and with surprisingly natural-sounding results.

In this article, we’ll walk through how to use the Core-Speech Kit to enable TTS in English and Japanese, despite the apparent language limitations in the documentation.

Background: What is Huawei Core-Speech Kit?

Huawei Core-Speech Kit is a part of Huawei Mobile Services (HMS), providing capabilities for speech synthesis (TTS) and speech recognition (ASR). While its documentation focuses heavily on Chinese language support, the TTS engine also works effectively with English and Japanese, making it a valuable tool for global applications.

What You’ll Learn

  • What TTS is and how it works
  • How to implement English/Japanese TTS using Huawei Core-Speech Kit
  • Working code examples in ArkTS and ArkUI
  • Practical limitations to keep in mind

Implementation: TTS in English and Japanese with Core-Speech Kit

Even though the default language is set to 'zh-CN' (Chinese), the engine automatically detects and speaks English or Japanese text fluently. Here’s how it’s done:

Step 1: Import Required Modules

import { textToSpeech } from '@kit.CoreSpeechKit';
import { BusinessError } from '@kit.BasicServicesKit';
Enter fullscreen mode Exit fullscreen mode

Step 2: Define the TTS Engine and Speak Function

let ttsEngine: textToSpeech.TextToSpeechEngine | null = null;

export function speakText(text: string) {
  if (!text || text.trim() === '') return;

  let initParams: textToSpeech.CreateEngineParams = {
    language: 'zh-CN', // Default language, but works with EN/JA input
    person: 0,
    online: 1,
    extraParams: {}
  };

  textToSpeech.createEngine(initParams, (err: BusinessError, engine) => {
    if (!err) {
      ttsEngine = engine;
      let uniqueId = `id-${new Date().getTime()}`;
      ttsEngine.speak(text, {
        requestId: uniqueId,
        extraParams: {}
      });
    } else {
      console.error(`TTS not started: ${err.message}`);
    }
  });
}
Enter fullscreen mode Exit fullscreen mode

Despite setting the language as 'zh-CN', the TTS engine successfully handles English and Japanese content with natural pronunciation.

Closing the TTS Engine

To avoid memory leaks or unexpected behavior, always shut down the engine after usage:

export function closeTTS() {
  if (ttsEngine) {
    ttsEngine.shutdown();
    console.info('TTS engine is closed.');
    ttsEngine = null;
  }
}
Enter fullscreen mode Exit fullscreen mode

Test Results: What Languages Work?

In a real-world test on an actual Huawei device, the Core-Speech Kit was able to synthesize speech from English and Japanese input accurately. However:

  • Korean is not supported for Text-to-Speech (although it works for OCR).
  • The TTS engine does not work on emulators or simulators. Only real devices (phones or tablets) are supported.

Conclusion

Even though the Core-Speech Kit is officially labeled for Chinese-only usage, developers can confidently implement multilingual TTS functionality, especially for English and Japanese. With just a few lines of TypeScript, you can empower your app with natural-sounding, cross-language voice synthesis — no hacks required.

If you’re building global applications with Huawei’s ecosystem, this is a neat trick to have in your toolkit.

References

Core Speech Kit
Core Vision Kit

Written by Mehmet Algul

Top comments (0)