Nowe posty

xx Problem ze sterownikami. (5)
2024-04-13, 21:25:16
xx Instalacja xfce4 (2)
2024-04-13, 16:20:17
xx Serie kompilacji bez instalacji dla “emerge” w Gentoo (2)
2024-04-08, 18:40:04
xx Plasma 6 w Neonie ssie trochę mniej ... (17)
2024-04-05, 10:03:46
xx Problem z Linux Lite po instalacji (3)
2024-04-03, 14:23:40
xx Jak właczyć num locka przy starcie systemu debian 12? (12)
2024-04-02, 17:43:54
xx Brak dźwieku w systemie. (5)
2024-04-02, 16:13:41
xx Dystrybucja pod HP Omen (7)
2024-03-29, 11:33:05
xx [Poradnik] Wyszukiwanie Sterowników (2)
2024-03-27, 21:08:23
xx Ile pingwinów? (1)
2024-03-27, 08:59:24

Autor Wątek: Odczyt ze strumienia  (Przeczytany 2355 razy)

riggs

  • Gość
Odczyt ze strumienia
« dnia: 2015-01-29, 19:19:38 »
Hej!

Mam problem, ktory nie moge juz od paru dni sam rozwiazac:

napisalem krotki program (test.c), ktory ma odczytywac dane tekstowe z innego programu i wyswietlac je (na razie) na ekranie.

#include 

char bufor[255];

int main()
{

  while ( fgets(bufor, sizeof(bufor), stdin ) )
  {
    printf("%s", bufor);
  }

return 0;
}
Program dziala jezeli wpisuje dowolny text z klawiatury, wyswietla tez text z pliku textowego:
./test < julek.txt
niestety nie dziala prawidlowo  jezeli chce odcyztac strumien z innego programu i przekierowac do pliku:
(julius -input mic -C julian.jconf | ./test ) > julek.txt
(julius jest programem do rozpoznawania mowy i podaje na konsole rozpoznane wyrazy i ewent. kometarze )

plik julek.txt zapisuje sie do 8.2kb. i koniec, zatrzymujem sie w tym samym miejscu,
po rozpoznaniu 1 wyrazu, wczesniej laduje sie initializacja juliusa, ustawienia itp. i
nastepuje oczyekiwanie na mowienie "<<< please speak >>>"

Probowalem zrobic tak:

julius -input mic -C julian.jconf > julek.txt
dlugosc pliku julek, jest prawidlowa i zalezna od dlugosci dzialania programu julius

potem ten  plik sprobowalem wczytac do mojego programiku

./test < julek.txt
i wszystko jest wyswietlane jak byc powinno.

Moze ktos ma jakis pomysl ? Wiem ze programy napisane w pythonie wspolpracuja  z juliusem bez problemu..
Dzieki!

płona

  • Gość
Odczyt ze strumienia
« Odpowiedź #1 dnia: 2015-01-30, 20:07:13 »
Wygląda na to, że julius buforuje wyjście na stdout i czeka na jakiś sygnał, że już skończyłeś gadać.
Napisz, jak kończysz juliusa w tym przypadku:
julius -input mic -C julian.jconf > julek.txt
może to coś rozjaśni

riggs

  • Gość
Odczyt ze strumienia
« Odpowiedź #2 dnia: 2015-01-30, 20:47:01 »
Po wykonaniu:

julius -input mic -C julian.jconf > julek.txt

po chwili na ekranie pojawia sie napis: >>>please speak <<< a plik julek.txt uzyskuje wielkosc 7,8 kb w tym momencie mowie cos do mikrofonu i napis >>>please speake<<< znika i po skonczeniu mowienia znowu sie pojawia, a plik textowy rosnie do 8.1 kb, powtarzam to i wartosc zwiekasza sie do 8,2 kb , a jak cos dluzej mowie to do 8,5kb, program koncze ctrl + c.

a to zawartosc pliku julek.txt z wyzej opisanej sesji:

STAT: include config: julian.jconf
STAT: jconf successfully finalized
STAT: *** loading AM00 _default
Stat: init_phmm: Reading in HMM definition
Stat: rdhmmdef: ascii format HMM definition
Stat: rdhmmdef: limit check passed
Stat: check_hmm_restriction: an HMM with several arcs from initial state found: "sp"
Stat: rdhmmdef: this HMM requires multipath handling at decoding
Stat: init_phmm: defined HMMs:  8318
Stat: init_phmm: loading ascii hmmlist
Stat: init_phmm: logical names:  9430 in HMMList
Stat: init_phmm: base phones:    44 used in logical
Stat: init_phmm: finished reading HMM definitions
STAT: making pseudo bi/mono-phone for IW-triphone
Stat: hmm_lookup: 1086 pseudo phones are added to logical HMM list
STAT: *** AM00 _default loaded
STAT: *** loading LM00 _default
STAT: reading [grammar/sample.dfa] and [grammar/sample.dict]...
Stat: init_voca: read 34 words
STAT: done
STAT: Gram #0 sample registered
STAT: Gram #0 sample: new grammar loaded, now mash it up for recognition
STAT: Gram #0 sample: extracting category-pair constraint for the 1st pass
STAT: Gram #0 sample: installed
STAT: Gram #0 sample: turn on active
STAT: grammar update completed
STAT: *** LM00 _default loaded
STAT: ------
STAT: All models are ready, go for final fusion
STAT: [1] create MFCC extraction instance(s)
STAT: *** create MFCC calculation modules from AM
STAT: AM 0 _default: create a new module MFCC01
STAT: 1 MFCC modules created
STAT: [2] create recognition processing instance(s) with AM and LM
STAT: composing recognizer instance SR00 _default (AM00 _default, LM00 _default)
STAT: Building HMM lexicon tree
STAT: lexicon size: 485 nodes
STAT: coordination check passed
STAT: multi-gram: beam width set to 200 (guess) by lexicon change
STAT: wchmm (re)build completed
STAT: SR00 _default composed
STAT: [3] initialize for acoustic HMM calculation
Stat: outprob_init: state-level mixture PDFs, use calc_mix()
Stat: addlog: generating addlog table (size = 1953 kB)
Stat: addlog: addlog table generated
STAT: [4] prepare MFCC storage(s)
STAT: [5] prepare for real-time decoding
STAT: All init successfully done

STAT: ###### initialize input device
----------------------- System Information begin ---------------------
JuliusLib rev.4.2.2 (fast)

Engine specification:
 -  Base setup   : fast
 -  Supported LM : DFA, N-gram, Word
 -  Extension    :
 -  Compiled by  : gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall

------------------------------------------------------------
Configuration of Modules

 Number of defined modules: AM=1, LM=1, SR=1

 Acoustic Model (with input parameter spec.):
 - AM00 "_default"
hmmfilename=acoustic_model_files/hmmdefs
hmmmapfilename=acoustic_model_files/tiedlist

 Language Model:
 - LM00 "_default"
grammar #1:
   dfa  = grammar/sample.dfa
   dict = grammar/sample.dict

 Recognizer:
 - SR00 "_default" (AM00, LM00)

------------------------------------------------------------
Speech Analysis Module(s)

[MFCC01]  for [AM00 _default]

 Acoustic analysis condition:
      parameter = MFCC_0_D_N_Z (25 dim. from 12 cepstrum + c0, abs energy supressed with CMN)
sample frequency = 16000 Hz
  sample period =  625  (1 = 100ns)
    window size =  400 samples (25.0 ms)
    frame shift =  160 samples (10.0 ms)
   pre-emphasis = 0.97
   # filterbank = 24
  cepst. lifter = 22
     raw energy = False
energy normalize = False
   delta window = 2 frames (20.0 ms) around
    hi freq cut = OFF
    lo freq cut = OFF
zero mean frame = OFF
      use power = OFF
            CVN = OFF
           VTLN = OFF
    spectral subtraction = off
  cepstral normalization = real-time MAP-CMN
base setup from = Julius defaults

 MAP-CMN:
      initial cep. data   = none
      beginning data weight = 100.00
    beginning data update = yes, from last inputs at each input

------------------------------------------------------------
Acoustic Model(s)

[AM00 "_default"]

 HMM Info:
    8318 models, 7542 states, 7542 mpdfs, 7542 Gaussians are defined
     model type = context dependency handling ON
      training parameter = MFCC_N_D_Z_0
  vector length = 25
number of stream = 1
    stream info = [0-24]
cov. matrix type = DIAGC
  duration type = NULLD
max mixture size = 1 Gaussians
     max length of model = 5 states
     logical base phones = 44
       model skip trans. = exist, require multi-path handling
      skippable models = sp (1 model(s))

 AM Parameters:
        Gaussian pruning = safe  (-gprune)
  top N mixtures to calc = 2 / 0  (-tmix)
    short pause HMM name = "sp" specified, "sp" applied (physical)  (-sp)
  cross-word CD on pass1 = handle by approx. (use max. prob. of same LC)
   sp transition penalty = -70.0

------------------------------------------------------------
Language Model(s)

[LM00 "_default"] type=grammar

 DFA grammar info:
      9 nodes, 17 arcs, 16 terminal(category) symbols
      category-pair matrix: 104 bytes (1632 bytes allocated)

 Vocabulary Info:
        vocabulary size  = 34 words, 129 models
        average word len = 3.8 models, 11.4 states
       maximum state num = 24 nodes per word
       transparent words = not exist
       words under class = not exist

 Parameters:
   found sp category IDs =

------------------------------------------------------------
Recognizer(s)

[SR00 "_default"]  AM00 "_default"  +  LM00 "_default"

 Lexicon tree:
total node num =    485
 root node num =     33
 leaf node num =     34

(-penalty1) IW penalty1 = +5.0
(-penalty2) IW penalty2 = +20.0
(-cmalpha)CM alpha coef = 0.050000

inter-word short pause = on (append "sp" for each word tail)
 sp transition penalty = -70.0
 Search parameters:
   multi-path handling = yes, multi-path mode enabled
(-b) trellis beam width = 200 (-1 or not specified - guessed)
(-bs)score pruning thres= disabled
(-n)search candidate num= 1
(-s)  search stack size = 500
(-m)    search overflow = after 2000 hypothesis poped
       2nd pass method = searching sentence, generating N-best
(-b2)  pass2 beam width = 200
(-lookuprange)lookup range= 5  (tm-5 <= t (-sb)2nd scan beamthres = 200.0 (in logscore)
(-n)        search till = 1 candidates found
(-output)    and output = 1 candidates out of above
IWCD handling:
  1st pass: approximation (use max. prob. of same LC)
  2nd pass: loose (apply when hypo. is popped and scanned)
all possible words will be expanded in 2nd pass
build_wchmm2() used
lcdset limited by word-pair constraint
short pause segmentation = off
fall back on search fail = off, returns search failure

------------------------------------------------------------
Decoding algorithm:

1st pass input processing = real time, on-the-fly
1st pass method = 1-best approx. generating indexed trellis
output word confidence measure based on search-time scores

------------------------------------------------------------
FrontEnd:

 Input stream:
            input type = waveform
          input source = microphone
   device API          = default
         sampling freq. = 16000 Hz
        threaded A/D-in = supported, on
  zero frames stripping = off
        silence cutting = on
            level thres = 2000 / 32767
        zerocross thres = 60 / sec.
            head margin = 300 msec.
            tail margin = 400 msec.
             chunk size = 1000 samples
   long-term DC removal = off
     reject short input = off

----------------------- System Information end -----------------------

*************************************************************
* NOTICE: The first input may not be recognized, since      *
*         no initial CMN parameter is available on startup. *
* for MFCC01*
*************************************************************

Stat: capture audio at 16000Hz
Stat: adin_alsa: latency set to 32 msec (chunk = 512 bytes)
Error: adin_alsa: unable to get pcm info from card control
Warning: adin_alsa: skip output of detailed audio device info
STAT: AD-in thread created
pass1_best: LIGHT FIVE
sentence1: LIGHT ONE
pass1_best: LIGHT FIVE
sentence1: LIGHT ON
pass1_best: LIGHT
WARNING: 00 _default: hypothesis stack exhausted, terminate search now
STAT: 00 _default: 0 sentences have been found

pass1_best: LIGHT FIVE
WARNING: 00 _default: hypothesis stack exhausted, terminate search now
STAT: 00 _default: 0 sentences have been found

Offline ultr

  • Users
  • Guru
  • *****
  • Wiadomości: 1177
    • Zobacz profil
Odczyt ze strumienia
« Odpowiedź #3 dnia: 2015-01-31, 09:47:55 »
Dodaj flusha za printf:
fflush(stdout);
Oraz obsługę sygnałów:
#include 
...
void handler(int signum)
{
    fflush(stdout);
    exit(0);
}
...
    struct sigaction action;
    memset(&action, 0, sizeof(struct sigaction));
    action.sa_handler = handler;
    sigaction(SIGINT, &action, NULL);
    sigaction(SIGTERM, &action, NULL);
...

riggs

  • Gość
Odczyt ze strumienia
« Odpowiedź #4 dnia: 2015-01-31, 15:46:48 »
Dziala! Dziekuje!!

Tylko podczas kompilacji :

gcc test.c -o test
wywala mi ostrzezenia:

test.c: In function 'handler':
test.c:9:5: warning: incompatible implicit declaration of built-in function 'exit' [enabled by default]
     exit(0);
     ^
test.c: In function 'main':
test.c:18:5: warning: incompatible implicit declaration of built-in function 'memset' [enabled by default]
     memset(&action, 0, sizeof(struct sigaction));
I jeszcze male pytanko ;)

Dlaczego Julius potrzebuje obslugi sygnalow? To kwestia ilosci informacji, ktore przekazuje do strumienia, czy tez sposobu ? Pytam, bo wczesniej napisalem male programiki, ktore wymienialy sie poprzez printf/scanf bez problemu?

Jeszcze raz Dzieki!