About

The code illustrates using narrator.device in order to speak the string Good day from Wizardry and Steamworks!. It is meant to run on OS2 where narrator.device is available but will work on OS3 as well provided that the following AmiNET packages and their requirements are added:

  • util/libs/Tran43pch.lha
  • util/libs/ax_2USA.lha
  • util/libs/Translator42.lha
  • narrator.device taken from Workbench 2.0

Code

speak.c
/*************************************************************************/
/*    Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3    */
/*************************************************************************/
/*                                                                       */
/*  speak                                                                */
/*                                                                       */
/*  Speaks the defined text using the narrator device which can be found  */
/*  on OS2. In order for the program to be compatible with OS3, the OS2  */
/*  files must be copied to the current workbench and the narrator        */
/*  device added.                                                        */
/*                                                                       */
/*  Compile using SASC: sc link speak.c                                  */
/*                                                                       */
/*************************************************************************/
 
#include <exec/types.h>
#include <exec/exec.h>
#include <dos/dos.h>
#include <devices/narrator.h>
 
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
 
#include <string.h>
#include <stdio.h>
 
#define TEXT "Good day from Wizardry and Steamworks!"
 
int main(void) {
    struct  MsgPort     *VoiceMP;
    struct  narrator_rb *VoiceIO;
    BYTE audio_chan[4] = { 3, 5, 10, 12 };
 
    UBYTE PhonBuffer[500];       /* place to put the translation */
    LONG rtnCode;                /* return code from translation function */
 
    /* Create message port. */
    if (!(VoiceMP = CreateMsgPort())) {
        printf("Error: Could not create message port.\n");
        return 1;
    }
 
    /* Create I/O request. */
    if (!(VoiceIO = CreateIORequest(VoiceMP, sizeof(struct narrator_rb)))) {
        printf("error: could not create I/O request.\n");
        return 1;
    }
 
    /* Open narrator device (from WB <= 2.0). */
    if (OpenDevice("narrator.device", 0, (struct IORequest*)VoiceIO, 0L)) {
        printf("error: could not open narrator.device.\n");
        return 1;
    }
 
    /* Translate text to phonemes. */
    rtnCode = Translate(TEXT, strlen(TEXT), (APTR)&PhonBuffer[0], 500);
 
    VoiceIO->ch_masks = &audio_chan[0];
    VoiceIO->nm_masks = sizeof(audio_chan);
    VoiceIO->message.io_Command = CMD_WRITE;
    VoiceIO->message.io_Offset = 0;
    VoiceIO->message.io_Data = PhonBuffer;
    VoiceIO->message.io_Length = strlen(PhonBuffer);
    DoIO((struct IORequest*)VoiceIO);
 
    /* Close the narrator device */
    CloseDevice((struct IORequest*)VoiceIO);
 
    return 0;
}

amiga/development/os2/speak.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.