Use Delphi to realize text file display and sound synchronization

Source: Internet
Author: User

In some language teaching software, often uses the text display and the sound synchronization playback, we may use the Delphi realization.

First, the production of materials

First, we select a few articles, here we choose Martin Luther King, Lincoln and Ronald Reagan's speeches, each article divides into several sentences, when makes the sound file, notes each sentence start time and the end time, then records it in a data table, this table has the following fields: NO, TEXT, StartTime, Represents the ordinal, content, and start time of each sentence.

Second, the production of the interface

Create a new project in Delphi, put multimedia control in form, Rich Text Editor, command button, radio group box, datasheet, clock and label, as shown

Properties of individual controls

1. The AutoEnable and AutoOpen properties of the multimedia control are set to false, and the Visiblebuttons attribute sets the record, Eject, and step as invisible.

2. The table control's databasename is set to the directory where the tables are stored, and we store the application, sound files, and tables in the Myprog directory, so DatabaseName is set to C:\myprog here, Set TableName to the name of the datasheet that corresponds to the default playback file, which is set to EX1.DBF.

3, the caption of the Radiogroup control is set to ' Please select the playback content ', add three lines to the Itmes feature: Martin Luther King, Lincoln, Ronald Reagan.

4, RichEdit control of the lines characteristics plus ' speech content.

Iv. Code Writing

1. Variable declaration

var isend:Boolean;
CurrentButton:TMPBtnType;
CurrentPlay,CurrentDisp:longint;

Where isend indicates whether playback has been to the end, Currentbutton indicates which button is pressed in the current MediaPlayer component, Currentplay, Currentdisp represents the current playback record and the current display record.

2, in the Formcreate incident to do some necessary preparatory work, the code is as follows:

procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.TableName:=ex1.dbf; Table1.Open;
MediaPlayer1.FileName:=ex1.wav;MediaPlayer1.Open;
MediaPlayer1.TimeFormat:=tfMilliseconds;
isend:=False;
CurrentButton:=btStop;
CurrentDisp:=1;
CurrentPlay:=1;
end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.