目录

TextReader (Read Control)

The read control TextReader uses AI capabilities to convert text into voice in real time and read the voice aloud. It is applicable to text browsing apps such as news and novels apps, helping users efficiently obtain information through text reading in scenarios where text content cannot be directly browsed.

Start version: 5.0.0(12)

Module Import

import { TextReader } from '@kit.SpeechKit';

init

init(context: common.BaseContext, readParams: ReaderParam): Promise<void>

Initializes the TextReader, that is, the TTS engine and underlying player. If the initialization fails, the corresponding error code is returned.

This API returns the result asynchronously through a promise. To configure long-duration permissions, please refer to step 8 in the development guide.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

context

common.BaseContext

Yes

App context.

readParams

ReaderParam

Yes

Reading parameters.

Returns:

Type

Description

Promise<void>

Promise object. No result is returned.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

201

Permission denied. Interface caller does not have permission "ohos.permission.KEEP_BACKGROUND_RUNNING".

401

Parameter error.

1010600011

Initialize failed.

Example:
import { TextReader } from '@kit.SpeechKit';
import { BusinessError } from '@kit.BasicServicesKit';

// Obtain app context.
let context: Context = getContext(this);
// Set reading parameters.
const readerParams: TextReader.ReaderParam = {
  isVoiceBrandVisible: true,
  businessBrandInfo: {
    panelName: 'AI Reader',
    panelIcon: $r('app.media.startIcon')
  }
};
// Initialize the TextReader.
TextReader.init(context, readerParams).then(() => {
  console.info(`TextReader succeeded in initializing.`);
}).catch((e: BusinessError) => {
  console.error(`TextReader failed to initialize. Code: ${e.code}, message: ${e.message}`);
})

start

start(readInfoList: ReadInfo[], articleId?: string): Promise<void>

Shows the player panel and starts playback. If the playback fails, the corresponding error code is returned.

This API returns the result asynchronously through a promise.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

readInfoList

ReadInfo[]

Yes

List of articles to read.

articleId

string

No

Article ID. If articleId is not passed, the playback starts from the first article in the article list by default. If articleId is passed, the playback starts from this specified article. (The article ID must be unique. Otherwise, the first article with the same ID will be automatically read when you access the articles with the same ID from the list.)

callbackParam

string

No

Custom parameter of your app.

Returns:

Type

Description

Promise<void>

Promise object. No result is returned.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter error.

1010600012

The TextReader is not initialized.

1010600013

Text-to-speech engine error.

1010600014

AudioRenderer play error.

1010600015

Audio decode error.

1010600016

AVSession error.

1010600017

Other error.

Example:
import { TextReader } from '@kit.SpeechKit';
import { BusinessError } from '@kit.BasicServicesKit';

const readInfoList: TextReader.ReadInfo[] = [{
  id: '001',
  title: {
    text:'Title of the text to read',
    isClickable:true
  },
  author:{
    text:'Author of the text to read',
    isClickable:true
  },
  date: {
    text:'2024/01/01',
    isClickable:false
  },
  bodyInfo: 'Text body to read'
}];
// Start the TextReader.
TextReader.start(readInfoList).then(() => {
  console.info(`TextReader succeeded in starting`);
}).catch((e: BusinessError) => {
  console.error(`TextReader failed to start. Code: ${e.code}, message: ${e.message}`);
})

stop

stop(): Promise<void>

Stops reading, closes the playback panel, deregisters the listener, and resets parameters.

This API returns the result asynchronously through a promise.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Returns:

Type

Description

Promise<void>

Promise object. No result is returned.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

Example:
import { TextReader } from '@kit.SpeechKit';
import { BusinessError } from '@kit.BasicServicesKit';

TextReader.stop().then(() => {
  console.info(`TextReader succeeded in stopping.`);
}).catch((e: BusinessError) => {
  console.error(`TextReader failed to stop. Code: ${e.code}, message: ${e.message}`);
})

release

release(): Promise<void>

Releases all resources of the TextReader.

This API returns the result asynchronously through a promise.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Returns:

Type

Description

Promise<void>

Promise object. No result is returned.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

Example:
import { TextReader } from '@kit.SpeechKit';
import { BusinessError } from '@kit.BasicServicesKit';

TextReader.release().then(() => {
  console.info(`TextReader succeeded in releasing.`);
}).catch((e: BusinessError) => {
  console.error(`TextReader failed to release. Code: ${e.code}, message: ${e.message}`);
})

pause

pause(): void

Pauses playback.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.pause();
} catch (e) {
  console.error(`TextReader failed to pause. Code: ${e.code}, message: ${e.message}`);
}

resume

resume(): void

Resumes playback.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

1010600013

TTS speak error.

1010600014

AudioRenderer play error.

1010600015

Audio decode error.

1010600016

AvSession error.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.resume();
} catch (e) {
  console.error(`TextReader failed to resume. Code: ${e.code}, message: ${e.message}`);
}

playPrev

playPrev(): void

Plays the previous article.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

1010600017

playPrev failed.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.playPrev();
} catch (e) {
  console.error(`TextReader failed to play previous article. Code: ${e.code}, message: ${e.message}`);
}

playNext

playNext(): void

Plays the next article.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

1010600018

playNext failed.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.playNext();
} catch (e) {
  console.error(`TextReader failed to play next article. Code: ${e.code}, message: ${e.message}`);
}

hidePanel

hidePanel(): void

Hides the playback panel.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.hidePanel();
} catch (e) {
  console.error(`TextReader failed to hide panel. Code: ${e.code}, message: ${e.message}`);
}

showPanel

showPanel(): void

Shows the playback panel.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

1010600012

The TextReader is not initialized.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.showPanel();
} catch (e) {
  console.error(`TextReader failed to show panel. Code: ${e.code}, message: ${e.message}`);
}

queryReadState

queryReadState(id?: string): ReadState

Queries the article reading status.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

id

string

No

Article ID.

Returns:

Type

Description

ReadState

Article reading status.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter error.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  let readState = TextReader.queryReadState('article_01');
  console.info(`Succeeded in querying read state, read state: ${JSON.stringify(readState)}`);
} catch(e) {
  console.error(`TextReader failed to queryReadState. Code: ${e.code}, message: ${e.message}`);
}

setArticleContent

setArticleContent(id: string, content?: string): void

Sets the article content.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

id

string

Yes

Article ID.

content

string

No

Article content. If content is not passed or is left empty, the control content page will show a loading failure message when the article with a specific ID is to be played. If content is passed, it indicates the content of the article with the specified ID.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter error.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.setArticleContent('article_01', 'Text body to read');
} catch (e) {
  console.error(`TextReader failed to setArticleContent. Code: ${e.code}, message: ${e.message}`);
}

setArticle

setArticle(readInfo: ReadInfo): void

Sets the article information.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

readInfo

ReadInfo

Yes

Article information, including images and content.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter error.

Example:
import { TextReader } from '@kit.SpeechKit';
import { image } from '@kit.ImageKit';

const readInfo: TextReader.ReadInfo = {
  id: '001',
  title: {
    text:'Title of the text to read',
    isClickable:true
  },
  author:{
    text:'Author of the text to read',
    isClickable:true
  },
  date: {
    text:'2024/01/01',
    isClickable:false
  },
  bodyInfo: 'Text body to read',
  image: {} as image.PixelMap
};
try {
  TextReader.setArticle(readInfo);
} catch (e) {
  console.error(`TextReader failed to setArticle. Code: ${e.code}, message: ${e.message}`);
}

loadMore

loadMore(readInfos: ReadInfo[], isEnd: boolean): void

Loads more articles to the article list. This API must be called after init and start are called in the project. You are advised to use this API in the 'requestMore' operation listener.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

readInfos

ReadInfo[]

Yes

List of articles to load.

isEnd

boolean

Yes

Indicates whether more content needs to be loaded.

  • true: All content has been loaded.
  • false: Some content is not completely loaded.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter error.

Example:
import { ReadStateCode, TextReader, TextReaderIcon } from '@kit.SpeechKit';

@Entry
@Component
struct Index {

  @State readInfoList: TextReader.ReadInfo[] = [];
  @State readState: ReadStateCode = ReadStateCode.WAITING;
  @State isInit: boolean = false;
  @State selectedReadInfo: TextReader.ReadInfo = this.readInfoList[0];
  async aboutToAppear(){
    /**
     * Load the data.
     */
    console.info(`ReadStateCode: ${JSON.stringify(this.readState)}`);
    let readInfoList: TextReader.ReadInfo[] = [{
      id: '001',
      title: {
    text:'Title of the text to read',
        isClickable:true
      },
      author:{
    text:'Author of the text to read',
        isClickable:true
      },
      date: {
        text:'2024/01/01',
        isClickable:false
      },
  bodyInfo: 'Text body to read'
    }];
    this.readInfoList = readInfoList;
    this.selectedReadInfo = this.readInfoList[0];
  }

  // Set the operation listener.
  setActionListener() {
    //...
    TextReader.on('requestMore', () => {
      console.info(`requestMore`);
      try {
        console.info(`loadMore`);
        TextReader.loadMore(this.readInfoList, true);
      } catch (e) {
        console.error(`TextReader failed to loadMore. Code: ${e.code}, message: ${e.message}`);
      }
    });
  }

  build() {
    Column() {
      TextReaderIcon({ readState: this.readState })
        .margin({ right: 20 })
        .width(32)
        .height(32)
        .onClick(async () => {
          try {
            this.setActionListener();
            await TextReader.start(this.readInfoList, this.selectedReadInfo?.id);
          } catch(e) {
            console.error(`TextReader failed to start`);
          }
        })
    }
    .height('100%')
  }
}

on(type: 'setArticle')

on(type: 'setArticle', callback: Callback<string>): void

Registers an article setting, which is triggered if the target article is empty (bodyInfo being empty) when an article is tapped or switched.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'setArticle' triggers the callback when the target article is empty (bodyInfo being empty) during article setting.

callback

Callback<string>

Yes

Callback executed when an article is tapped or switched, with the article ID.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('setArticle', (id: string) => {
    console.info(`Succeeded in setting setArticleListener: ${id}`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'setArticle')

off(type: 'setArticle', callback?: Callback<string>): void

Deregisters an article setting, which is used after on(type: 'setArticle') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'setArticle' triggers the callback when an article is set.

callback

Callback<string>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('setArticle');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'clickArticle' | 'clickAuthor' | 'clickNotification')

on(type: 'clickArticle' | 'clickAuthor' | 'clickNotification', callback: Callback<string>): void

Registers the tap event, which is triggered when the title, author, or notification bar is tapped.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'clickArticle': The article title is tapped.
  • 'clickAuthor': The article author is tapped.
  • 'clickNotification': The notification bar is tapped. Reserved value, which is not supported currently.

callback

Callback<string>

Yes

Tap event callback with the article ID.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('clickArticle', (id: string) => {
    console.info(`Succeeded in setting clickArticleListener: ${id}`);
  });
  TextReader.on('clickAuthor', (id: string) => {
    console.info(`Succeeded in setting clickAuthorListener: ${id}`);
  });
  TextReader.on('clickNotification', (id: string) => {
    console.info(`Succeeded in setting clickNotificationListener: ${id}`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'clickArticle' | 'clickAuthor' | 'clickNotification')

off(type: 'clickArticle' | 'clickAuthor' | 'clickNotification', callback?: Callback<string>): void

Deregisters a tap event, which is used after on(type: 'clickArticle' | 'clickAuthor' | 'clickNotification') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'clickArticle': The article title is tapped.
  • 'clickAuthor': The article author is tapped.
  • 'clickNotification': The notification bar is tapped.

callback

Callback<string>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('clickArticle');
  TextReader.off('clickAuthor');
  TextReader.off('clickNotification');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'showPanel' | 'hidePanel')

on(type: 'showPanel' | 'hidePanel', callback: Callback<void>): void

Callback triggered when the playback panel is shown or hidden.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'showPanel': The panel is shown.
  • 'hidePanel': The panel is hidden.

callback

Callback<void>

Yes

Panel event callback.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:
import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('showPanel', () => {
    console.info(`Succeeded in setting showPanelListener.`);
  });
  TextReader.on('hidePanel', () => {
    console.info(`Succeeded in setting hidePanelListener.`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'showPanel' | 'hidePanel')

off(type: 'showPanel' | 'hidePanel', callback?: Callback<void>): void

Deregisters the listening event for showing or hiding the playback panel, which is used after on(type: 'showPanel' | 'hidePanel') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'showPanel': The panel is shown.
  • 'hidePanel': The panel is hidden.

callback

Callback<void>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('showPanel');
  TextReader.off('hidePanel');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'stop' | 'release')

on(type: 'stop' | 'release', callback: Callback<void>): void

Callback triggered when stop or release is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'stop': The stop API is called or a user exits by swiping the notification bar.
  • 'release': The release API is called to release resources.

callback

Callback<void>

Yes

Callback of the stop/release event.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('stop', () => {
    console.info(`Succeeded in setting stopListener.`);
  });
  TextReader.on('release', () => {
    console.info(`Succeeded in setting releaseListener.`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'stop' | 'release')

off(type: 'stop' | 'release', callback?: Callback<void>): void

Deregisters the stop/release event, which is used after on(type: 'stop' | 'release') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'stop': The stop API is called or a user exits by swiping the notification bar.
  • 'release': The release API is called to release resources.

callback

Callback<void>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('stop');
  TextReader.off('release');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'stateChange')

on(type: 'stateChange', callback: Callback<ReadState>): void

Callback triggered when the status of the article that is being played changes.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'stateChange' triggers the callback when the status of the article that is being played changes.

callback

Callback<ReadState>

Yes

Callback executed when the status of the article that is being played changes.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('stateChange', (state: TextReader.ReadState) => {
    console.info(`Succeeded in setting stateChangeListener: ${JSON.stringify(state)}`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'stateChange')

off(type: 'stateChange', callback?: Callback<ReadState>): void

Deregisters the event indicating that the status of the article that is being played changes, which is used after on(type: 'stateChange') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'stateChange' triggers the callback when the status of the article that is being played changes.

callback

Callback<ReadState>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('stateChange');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'requestMore')

on(type: 'requestMore', callback: Callback<void>): void

Callback triggered when a user swipes the screen to the bottom of a reading list.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'requestMore' triggers the callback when more articles are requested.

callback

Callback<void>

Yes

Callback triggered when a user swipes the screen to the bottom of a reading list.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('requestMore', () => {
    console.info(`Succeeded in setting requestMoreListener.`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'requestMore')

off(type: 'requestMore', callback?: Callback<void>): void

Deregisters the event for swiping to the bottom of the reading list, which is used after on(type: 'requestMore') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'requestMore' triggers the callback when more articles are requested.

callback

Callback<void>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('requestMore');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'eventNotification' | 'eventPanel')

on(type: 'eventNotification' | 'eventPanel', callback: Callback<NotificationEvent| PanelEvent>): void

Callback triggered when the status of the notification bar and media controller or playback panel changes.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'eventNotification': The status of the notification bar and media controller changes.
  • 'eventPanel': The playback panel status changes. The BPC_10 click event callback in PanelEvent supports only mobile phones.

callback

Callback<NotificationEvent | PanelEvent>

Yes

Callback triggered when the status of the notification bar and media controller or playback panel changes.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('eventNotification', (ne: TextReader.NotificationEvent) => {
    console.info(`Succeeded in setting eventNotificationListener: ${JSON.stringify(ne)}`);
  });
  TextReader.on('eventPanel', (pe: TextReader.PanelEvent) => {
    console.info(`Succeeded in setting eventPanelListener: ${JSON.stringify(pe)}`);
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'eventNotification' | 'eventPanel')

off(type: 'eventNotification' | 'eventPanel', callback?: Callback<NotificationEvent | PanelEvent>): void

Used after on(type: 'eventNotification' | 'eventPanel') is called, to deregister the callback executed when the status of the notification bar and media controller or playback panel changes.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type.

  • 'eventNotification': The status of the notification bar and media controller changes.
  • 'eventPanel': The playback panel status changes.

callback

Callback<NotificationEvent | PanelEvent>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('eventNotification');
  TextReader.off('eventPanel');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

on(type: 'eventReadList')

on(type: 'eventReadList', callback: Callback<Array<ListEventState>>): void

Registers a listener for events related to the reading list. When an event related to the reading list occurs, the callback is triggered.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'eventReadList' is supported.

callback

Callback<Array<ListEventState>>

Yes

Callback executed when an event related to the reading list occurs.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.on('eventReadList', (list: Array<TextReader.ListEventState>) => {
    list.forEach((id) => {
      console.info(`Succeeded in setting eventReadListListener, article id: ${id}`);
    })
  });
} catch (e) {
  console.error(`TextReader failed to set eventListener. Code: ${e.code}, message: ${e.message}`);
}

off(type: 'eventReadList')

off(type: 'eventReadList', callback?: Callback<Array<ListEventState>>): void

Deregisters events related to the reading list, which is used after on(type: 'eventReadList') is called.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Mandatory

Description

type

string

Yes

Event callback type. The event 'eventReadList' is supported.

callback

Callback<Array<ListEventState>>

No

Callback for which listening is to be disabled. If this parameter is not specified, listening will be disabled for all callbacks of the event in the app.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

Error Code

Error Message

401

Parameter check failed.

Example:

import { TextReader } from '@kit.SpeechKit';

try {
  TextReader.off('eventReadList');
} catch (e) {
  console.error(`TextReader failed to unset eventListener. Code: ${e.code}, message: ${e.message}`);
}

ReaderParam

Reading parameters.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Name

Type

Read-Only

Optional

Description

isVoiceBrandVisible

boolean

No

No

Indicates whether to display the brand.

  • false (default): no
  • true: yes

businessBrandInfo

BusinessBrandInfo

No

Yes

Brand information.

isFastForward

boolean

No

Yes

Fast-forward and rewind logic.

  • false (default): by sentence
  • true: by 15 seconds

keepBackgroundRunning

boolean

No

Yes

Indicates whether the control keeps running in the background.

Reserved parameter, which is not supported currently.

To run the control in the background, set the permission for a long-duration task.

online

number

No

Yes

The synthesis mode is not online by default.

Synthesis mode. The options are as follows: 0: online; 1: offline.

Reserved parameter. Currently, only 1 is supported.

BusinessBrandInfo

Brand information.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Name

Type

Read-Only

Optional

Description

panelName

string

No

Yes

Service name displayed on the top of the playback panel.

panelIcon

ResourceStr

No

Yes

Service icon displayed on the top of the playback panel.

Reserved parameter, which is not supported currently.

notificationIcon

ResourceStr

No

Yes

Service icon displayed on the notification bar.

Reserved parameter, which is not supported currently.

notificationName

string

No

Yes

Service name displayed on the notification bar.

Reserved parameter, which is not supported currently.

ReadState

Reading status.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Name

Type

Read-Only

Optional

Description

id

string

No

No

Article ID.

state

ReadStateCode

No

No

Current reading status.

ReadInfo

Reading information.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Name

Type

Read-Only

Optional

Description

id

string

No

No

Article ID.

title

TextInfo

No

No

Title.

category

string

No

Yes

Category.

author

TextInfo

No

Yes

Author of an article.

date

TextInfo

No

Yes

Time of an article. Example: Mon Jul 08 2024 21:25:41 GMT+0800

Reserved parameter, which is not supported currently.

image

image.PixelMap

No

Yes

Cover image.

If this parameter is not passed, the default cover image is used.

bodyInfo

string

No

Yes

This parameter is mandatory for the setArticle and loadMore APIs.

Other text information read in real time (allowing a maximum of 10,000 Chinese characters).

TextInfo

Text information.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Read-Only

Optional

Description

text

string

No

No

Text.

isClickable

boolean

No

No

Indicates whether to support redirection by taps.

PanelEvent

Playback panel event.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Read-Only

Optional

Description

id

string

No

No

Article ID.

click

string

No

No

  • BPC_01: tapping the playback button
  • BPC_02: tapping the pause button
  • BPC_03: tapping the previous button
  • BPC_04: tapping the next button
  • BPC_05: tapping the speed button
  • BPC_06: tapping the timbre button
  • BPC_07: tapping the reading list
  • BPC_08: tapping the title
  • BPC_09: tapping the author
  • BPC_10: exiting the panel by tapping the arrow in the upper left corner or swiping down

NotificationEvent

Notification bar event.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Read-Only

Optional

Description

id

string

No

No

Article ID.

type

number

No

No

1: notification bar tap callback

2: media controller tap callback

click

string

No

No

  • NBC_01: tapping the playback button
  • NBC_02: tapping the pause button
  • NBC_03: tapping the close button
  • NBC_04: tapping the previous button
  • NBC_05: tapping the next button
  • NBC_06: tapping an image in an article (reserved)
  • NBC_07: tapping the title of an article (reserved)

ListEventState

List event status.

System capability: SystemCapability.AI.Component.TextReader

Start version: 5.0.0(12)

Parameters:

Name

Type

Read-Only

Optional

Description

id

string

No

No

Article ID.