HarmonyOS Application Development - Imitating WeChat Chat Message List
This example demonstrates how to create a chat application interface similar to WeChat using ArkTS. The page structure includes a scrollable message list and a button to dynamically add new messages. The core code is as follows: 1. The `Msg` class defines the message type (sent or received). 2. The `MsgDataSource` class implements the data source interface, manages the message list, and provides add/delete operations. 3. The page uses the `List` component to display the message list, with `LazyForEach` to dynamically load new messages as the user scrolls.
Read MoreHarmonyOS Application Development - Sending POST Request and Obtaining Result
This code is used to send data to the server via a POST request and parse the JSON response. The core functionalities include: 1. Using the `http.createHttp().request()` method to send asynchronous POST requests. 2. Setting request headers and the data to be sent. 3. Obtaining the response result and parsing it into JSON format. 4. Parsing the JSON data and extracting valid information to update the interface text. The code structure clearly demonstrates how to implement HTTP requests in a HarmonyOS application by setting state variables.
Read MoreHarmonyOS Application Development - Playing Local Audio Files
This document introduces the implementation of audio playback functionality on HarmonyOS using the AVPlayer audio and video player. The main steps include: 1. Creating an `AVPlayer` instance and registering callback functions to handle state changes and errors; 2. Obtaining the local audio file path, opening the audio file through file system operations to get the file descriptor, and setting it to `AVPlayer` to trigger resource initialization; 3. Implementing state machine transition logic, from resource initialization to playback completion. This code snippet demonstrates how to implement audio playback using the ArkTS language under the Stage model.
Read MoreHarmonyOS Application Development - Requesting Voice Synthesis Service to Obtain Audio File
This document describes a text-to-speech service implemented using HarmonyOS, which uploads text data and requests the server to return audio data. Key steps include creating HTTP requests, setting request headers and data bodies, processing response data, and saving it to a local file. The code example demonstrates how to integrate this functionality in an Ability, specifically implementing the download and saving of a .wav format voice file after the user inputs text. It should be noted that the service response type must be `application/octet-stream` to correctly obtain the audio stream, and this service is only applicable to... (The original text appears to be cut off here.)
Read MoreEasily Identify Long Audio/Video Files with Hours-Long Duration
This article introduces a method to build a long - speech recognition service capable of processing audio or video files that last tens of minutes or even several hours. First, the folder needs to be uploaded to the server, and then commands for compilation, permission modification, and starting the Docker container are executed to deploy the service. After testing that the service is available, the WebSocket interface or HTTP service can be used for interaction. The HTTP service provides a web interface, supporting the upload and recording recognition of audio and video in multiple formats, and returns text results containing the start and end timestamps of each sentence. This service simplifies the long - audio recognition process and improves user...
Read More