0
----G3wq

Com-data; name="Audio"; paramName="TEXT_TO_READ"

Content-Type: audio/x-wav;codec=pcm;bit=16;rate=16000

NContext: 6d46462d-f312-4352-bf01-0a220ed75ae4



ÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿÿÿÿÿþÿþÿþÿþÿýÿþÿþÿýÿÿÿÿÿÿÿ





    ÿÿÿÿýÿþÿýÿýÿúÿøÿúÿúÿúÿûÿþÿýÿùÿûÿüÿþÿüÿùÿúÿõÿ÷ÿóÿñÿôÿñÿïÿòÿñÿîÿîÿôÿóÿ÷ÿ÷ÿóÿõÿòÿïÿíÿðÿïÿ    ÿÿûÿïÿçÿäÿïÿïÿøÿþÿýÿóÿïÿèÿèÿàÿäÿæÿâÿìÿñÿ÷ÿøÿõÿõÿñÿïÿïÿðÿìÿæÿôÿõÿøÿúÿûÿøÿìÿóÿòÿýÿüÿûÿþÿýÿÿÿ÷ÿøÿüÿøÿõÿìÿïÿòÿ÷ÿúÿûÿ  üÿ÷ÿûÿ÷ÿ    
ÿÿÿÿòÿïÿïÿòÿýÿÿÿøÿõÿôÿîÿüÿ

þÿþÿùÿ#ÿÿøÿ
% :÷îfï

----N_NMSP_vutc5w1XobDdefsYG3wq

Content-Disposition: form-data; name="Audio"; paramName="TEXT_TO_READ"

Content-Type: audio/x-wav;codec=pcm;bit=16;rate=16000

Ne-Context: 6d46462d-f312-4352-bf01-0a220ed75ae4



‚ìÔáqâì÷ø
ûC\}IûÚ÷ö-ûMüäùøüï/˜?/.·\ÕîV’Š+³ÍcÛ¶Rúÿüÿ
âÿ±ÿ-×ÿbÿÖþ”þÓþ0ÿÎþ¾þÿ¬ÿœB“CéÛéŠ}¼ã,ÿ–ÿŽÿ=ÿ±þÿÀÅÿWÿ)N”õ¡Ïkÿîþ4þÒþ÷üÀüIýŸý¸þ'þ½üÅÿH’Z)ùÚ€ÿïûøüœýQýûúŠøéú‡þ‹âÿÿ…8^Í0Æ &ýwû?û?þbýú±ù)ÿè?´~¹¶’îuÿRýJü¡üÿ<þ¼þnþˆèr¢ÇnØnTÿûý©ý;üGû\ûsûëþ–ã‚óþt^Lçñ(»ýlÿ\K§™ýÀü—ý¢ÿ›þz ä¦ÿrÿÖ?à´åÿV=ÅiYRýÇýÿœ ‹®½éþåÿ¿ÿy‘Æýóüý%ý¦ÿ_•4ORò›³&U(ÿ?þTþ‹ÿ-ýŠúZú•ü4ÿjÿ«ûCüñþ’õ äïø‚þþ¢ÿÖþšû2úRú<üýõü¾ý~ýJG­FÕy(&èÿlþVÿ?þ‹ýÅý¤ÿwº®ÿäý—ÿœÛvþÜüýAû5þLþ!þü»ù|ü†þÂþÀÀþÉÿ“ãÙu­úNíÕ,þËü#ýfýÄæÿJþxü¶ý‘~596Žn…w?ÜGý‰ýöüáþÇþÖý7ÿœýVÿsÿC€´
öýøüþ¢”·’þ*ýBþýÝû9ýøú2üŸü   úJû²ú

ù‰ÿ·“û#÷Wü ý2yýþþ‰ýýòÿkÙÂûVüæÁâÿûù§ùAøýKoÎÿ0þð'ü™üºù%üòü? ¼7MH.Hýúɪ5YxqÿåÿñýIþÌ

FSÉþÛüõúdùü÷¿öMõèóšò?ñóð†ðsðAð5ðððòïÐï˜ïºïðjðÅðãð†ð
ð?ïï î'îî×í£íüììÎê?é€èÂççiæˆå¢äªãÔâÝáá>àäß-à±àá‰áwáCáŒá=â¥ãAå>ç éëÂìäî[ñô÷ú9ý¤›†7Ÿ? ʼd Œ#K&Y(*?+ù,%.Þ.Q/î/,00ˆ/§.«-$,ª*E)È'!&H$?"ï5+gHë|$¼>    ˜F
Ãÿ‹ýëûuúúøn÷øõÊôxóRò^ñ€ðöï^ïòî{îÇííwìþë›ëAëÝêªêQêþéŠéîèQèœçÞæ[æøåeåå{äïãã=â?ááóàá&á'áôà­à¸àá¬áµâÄãÚäæ,çeè¶é³ëêí„ðÓòõõ÷¿úçýoY;“»àÑO"Ý$R'§)–+z-Í.û/‡0Ý0!1J11s0‡/6.Ú,h+*?(ù%q#î y
kØ L©.} åCÐÿ³ý¯ûáùø{öÒôBóîñ…ð¢ïåî0î‚íÂì.ì²ëBëâêtêê›é9éçè¦èMèèÈçwç׿Fæäå˜åmåRå4åÚäZäöã?ãdã=ãWã¥ãäsäÈäå åfå;æ…çöèIêµë@íˆîðËñÞóþõ"øjú­ý`îéu
¡OÄ?ð÷„     "Ì#b%E&›'â(£)*-*ó)Ç)u)é(>(Â'?&J%Ë#á! íÁ‹%è¤wá)³2ìþþüûùïöõ9óQñ›ï=îíÀë©ê?é˜è¡ç¥æ¿ååqäääÙã¹ã?ãgãJããÖâÕâðâ1ã›ãýãKä9ääVäÀäJå+æSç@è¨è$éêIë£ìî›ïLñ
óõ<÷)ùúHü?þÿÍ–  %ýgôm¦âlLÎ0 a!  "š"<#È#ü#M$%±%/%ë#Ð","»!ó  «9¸´Åô6\
0ê>eÿþ#ý›ü½ûŠúQùaøÌ÷0÷Šöíõ’õBõïôˆôôyó*ó?óióŒó?óÑóô[ô‘ô´ôõôYõñõ‡öòöL÷{÷º÷û÷ ø?øxøîø‰ù6úÅúûoûÐûAü¡üýbý¶ý#þwþÿcÿuÿsÿzÿºÿïÿ!8A9(ÿÿÿÿÿÿÿÿ

----NMSP_vutc5w1XobDdefsYG3wq

Content-Disposition: form-data; name="QueryResult"

Content-Type: application/JSON; charset=utf-8

N-Context: 6d46462d-f312-4352-bf01-0a220ed75ae4

{"TTSStatus":"Success","result_type":"NVC_TTS_CMD","NMAS_PRFX_SESSION_ID":"23de3ddd-62b9-407c-88f0-1f81d7c1e475","NMAS_PRFX_TRANSACTION_ID":"1"}

---NNMSP_vutc5w1XobDdefsYG3wq--

I was just getting a header, binary data and TTSStatus from the server but now I am getting as above nothing but getting header, binary, header, binary and TTSStatus. The below code is working fine when I was just getting a header, binary data and TTSStatus from the server.

Can someone please tell me how to modify it ?

for part in msg.walk():
        content_type = part.get_content_type()
        payload = part.get_payload()
        try:
            #if there is no reference file exist then create one based on the response 

            if content_type == "audio/x-wav" and len(payload):
                ref_filename = get_filename('pcm', output_filename + '_ref', outputfolder)
                if not os.path.exists(ref_filename):
                    with open(ref_filename, 'wb') as f_pcm:
                        f_pcm.write(payload)

                else:
                    print "[Warning] Reference PCM file is already there"

                cur_filename = get_filename('pcm', output_filename, outputfolder)
                if len(cur_filename):
                    with open(cur_filename, 'wb') as f_pcm:
                        f_pcm.write(payload)

                else:
                    print "[ERROR] Not able to create a Response PCM file \n"

                Error_Status = compare_files(ref_filename, cur_filename)

            #copy the header or the json response from the server

            elif content_type == "application/json":
                with open(get_filename('json', output_filename, outputfolder), 'w') as f_json:
                    f_json.write(payload)
        except:
            print "\n[ERROR] Can't Create Reference PCM or Response JSON files!"
            Error_Status = 1
5
  • Martin Evans- can you please tell me how ? Commented Feb 23, 2016 at 20:15
  • Has the boundary changed on the MIME data? Try building data as follows: data = "MIME-Version: 1.0\nContent-Type: {}\n{}".format(res.getheader('content-type'), res.read()) Commented Feb 23, 2016 at 21:00
  • thanks. but it is not working. Commented Feb 23, 2016 at 21:05
  • Not sure what you have changed, the old code still works for me. Commented Feb 23, 2016 at 21:07
  • Martin Evans : I can explain like this : before I was giving input like ENG|I am tired - this text is small in length so my code was working properly and getting output in one segment. now the input is like ENG|I am hungry, so I am going to restaurant. Hence I am getting in segments. First I will get I am hungry then remaining input will be processed. I think . I have to modify the code in if content_type == "audio/x-wav" and len(payload): can you please tell me how ? Commented Feb 24, 2016 at 7:03

1 Answer 1

1

It appears you are sometimes getting two PCM blocks back for each request. Previously the second entry was empty.

The following will add a segment number to the end of each file. It is based on my original code, so you will need to apply the changes to your full current script:

    data = "MIME-Version: 1.0\nContent-Type: {}\n{}".format(res.getheader('content-type'), res.read())
    msg = email.message_from_string(data)
    segment = 1

    for part in msg.walk():
        content_type = part.get_content_type()
        payload = part.get_payload()

        if content_type == "audio/x-wav" and len(payload):
            pcm_filename = '{}_{}'.format(output_filename, segment)
            segment += 1

            ref_filename = get_filename('pcm', pcm_filename + '_ref', LNG)
            if not os.path.exists(ref_filename):
                with open(ref_filename, 'wb') as f_pcm:
                    f_pcm.write(payload)

            cur_filename = get_filename('pcm', pcm_filename, LNG)
            with open(cur_filename, 'wb') as f_pcm:
                f_pcm.write(payload)

            compare_files(ref_filename, cur_filename)

        elif content_type == "application/json":
            with open(get_filename('json', output_filename, LNG), 'w') as f_json:
                f_json.write(payload)

You could also change the following line:

output_filename = "".join([x if x.isalnum() else "_" for x in required_text[:80]]).replace('__', '_').strip('_')

This will have the effect of removing any double underscores or trailing underscores from your output file names.


Alternatively, if you want to append all of the segments together, you could try something like the following version. Unfortunately, I was not able to recreate the multi-segment response and so was not able to test this to see if it is possible to just append the various segments together and for it to still play correctly:

    data = "MIME-Version: 1.0\nContent-Type: {}\n{}".format(res.getheader('content-type'), res.read())
    msg = email.message_from_string(data)
    wav_data = []

    for part in msg.walk():
        content_type = part.get_content_type()
        payload = part.get_payload()

        if content_type == "audio/x-wav" and len(payload):
            wav_data.append(payload)
        elif content_type == "application/json":
            with open(get_filename('json', output_filename, LNG), 'w') as f_json:
                f_json.write(payload)

    if len(wav_data):
        payload = ''.join(wav_data)

        ref_filename = get_filename('pcm', output_filename + '_ref', LNG)
        if not os.path.exists(ref_filename):
            with open(ref_filename, 'wb') as f_pcm:
                f_pcm.write(payload)

        cur_filename = get_filename('pcm', output_filename, LNG)
        with open(cur_filename, 'wb') as f_pcm:
            f_pcm.write(payload)

        compare_files(ref_filename, cur_filename)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.