文本到语音 - 多个调用

时间:2017-02-03 13:24:44

标签: java text-to-speech

我正在写一个文本到语音程序。如果只对该类进行一次调用,它就可以正常工作,如下所示:

/**
 * Resizes a BMP piece by piece, just because.
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h> 
#include "bmp.h"

int main(int argc, char *argv[])
{
    // ensure proper usage
    if (argc != 4)
    {
        fprintf(stderr, "Usage: ./resize f infile outfile\n");
        return 1;
    }

    // convert string argument to float
    float f;
    sscanf(argv[1], " %f", &f);

    if(f > 100.0 || f < 0.0) {
        fprintf(stderr, "Usage: ./resize f infile outfile\n");
        return 1;
    }

    // remember filenames
    char *infile = argv[2];
    char *outfile = argv[3];

    // open input file 
    FILE *inptr = fopen(infile, "r");
    if (inptr == NULL)
    {
        fprintf(stderr, "Could not open %s.\n", infile);
        return 1;
    }

    // open output file
    FILE *outptr = fopen(outfile, "w");
    if (outptr == NULL)
    {
        fclose(inptr);
        fprintf(stderr, "Could not create %s.\n", outfile);
        return 1;
    }

    // read infile's BITMAPFILEHEADER
    BITMAPFILEHEADER bf, bfOut;
    fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
    bfOut = bf;

    // read infile's BITMAPINFOHEADER
    BITMAPINFOHEADER bi, biOut;
    fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
    biOut = bi;

    // ensure infile is (likely) a 24-bit uncompressed BMP 4.0
    if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || 
        bi.biBitCount != 24 || bi.biCompression != 0)
    {
        fclose(outptr);
        fclose(inptr);
        fprintf(stderr, "Unsupported file format.\n");
        return 4;
    }

    // determine padding for scanlines
    int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

    //update BITMAPINFOHEADER for new resized file
    biOut.biWidth = floor(bi.biWidth * f);
    biOut.biHeight = floor(bi.biHeight * f);

    // determine padding for output file's scanline
    int paddingOut = (4 - biOut.biWidth * sizeof(RGBTRIPLE) % 4) % 4;

    // calculate output file image size header
    biOut.biSizeImage = ((sizeof(RGBTRIPLE) * biOut.biWidth) + paddingOut) * abs(biOut.biHeight);

    //update BITMAPFILEHEADER for new resized file
    bfOut.bfSize = biOut.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

    // write outfile's BITMAPFILEHEADER
    fwrite(&bfOut, sizeof(BITMAPFILEHEADER), 1, outptr);

    // write outfile's BITMAPINFOHEADER
    fwrite(&biOut, sizeof(BITMAPINFOHEADER), 1, outptr);

    //create array in memory for storing scanline of inFile.width elements
    RGBTRIPLE *scanLine = (RGBTRIPLE *) malloc(sizeof(RGBTRIPLE) * bi.biWidth);


    // Iterate over inFile's scanlines one by one.
    int inRows =  abs(bi.biHeight), outRows = abs(biOut.biHeight), current = 0;

    for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
    {
        // iterate over pixels and store them in scanline
        for (int j = 0; j < bi.biWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

            // write RGB triple to scanline
            scanLine[j] = triple;
        }

        if(f< 1.0) {
            current += inRows/outRows;
            inRows -= floor(inRows/outRows);
            printf("%i\n", current);
            //***todo****
            //if(condition)
            //  continue;
            outRows--; 
        }

        //write scanline and padding to file n times verticlly 
        int ind;
        for(int m = 0;  m < ceil(f); m++) {

            //scanline
            for(int l = 0; l < biOut.biWidth; l++) {
                ind = l/f;
                fwrite(&scanLine[ind], sizeof(RGBTRIPLE), 1, outptr);
            }

            //padding
            for(int o = 0; o < paddingOut; o++) 
                fputc(0x00, outptr);

        }

        // skip over padding, if any
        fseek(inptr, padding, SEEK_CUR);
    }

    // cleanup
    free(scanLine);
    fclose(inptr);
    fclose(outptr);

    // success
    return 0;
}

但是当我尝试将同一个实例用于另一行时,它会出错:

Text2Speech obj=new Text2Speech();
obj.dospeak("Hello this actually works","kevin16");
  

java.lang.IllegalThreadStateException&GT;

     

C:\ Users \&#39; user&#39;

中缺少speech.properties

即使创建新对象仍然会产生相同的错误。同样,它将适用于第一次调用dospeak()方法;它是第二行不会被读出来的。

以下是源代码:

Text2Speech obj=new Text2Speech();
obj.dospeak("Hello this actually works","kevin16");
obj.dospeak("second line", "kevin16");

1 个答案:

答案 0 :(得分:0)

试试这个而不是&#34; dospeak&#34;。它对我有用:

{{1}}