반응형
반응형

[Python] argparse 사용법 (파이썬 인자값 추가하기)

 

두개의 인자 path, savefilename 을 받음.

(env) C:\__STT>python transcribe_async_gcs.py gs://cloud-samples-tests/speech/vr.flac 12345
Waiting for operation to complete...
Transcript: it's okay so what am I doing here why am I here at GDC talking about VR video it's because I believe my favorite games I love games I believe in games my favorite games are the ones that are all about the stories I love narrative game design I love narrative-based games and I think that when it comes to telling stories in VR bring together capturing the world with narrative based games and narrative based game design is going to unlock some of the killer apps and killer stories of the medium
Confidence: 0.9580045938491821
Transcript: so I'm really here looking for people who are interested in telling us or two stories that are planning projects around telling those types of stories and I would love to talk to you so if it sounds like your project if you're looking at blending VR video and interactivity to tell a story I want to talk to you I want to help you so if this sounds like you please get in touch with you can't find me I'll be here all week I have pink hair I work for Google and I would love to talk with you further about VR video interactivity and storytelling
Confidence: 0.949270486831665
completed
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument("path", help="File or GCS path for audio file to be recognized")  
    parser.add_argument("savefilename", help="Save fileName ")   
    args = parser.parse_args()

    response = transcribe_gcs(args.path)
    
    with open("stt_"+args.savefilename+".txt", "w") as script:
        for result in response.results:
            script.write(u'Transcript: {}'.format(result.alternatives[0].transcript)+"\n")
            script.write(u'Confidence: {}'.format(result.alternatives[0].confidence)+"\n")
            script.write(u'Channel Tag: {}'.format(result.alternatives[0].channel_tag)+"\n")

docs.python.org/ko/3/library/argparse.html

 

argparse — 명령행 옵션, 인자와 부속 명령을 위한 파서 — Python 3.9.0 문서

argparse — 명령행 옵션, 인자와 부속 명령을 위한 파서 소스 코드: Lib/argparse.py argparse 모듈은 사용자 친화적인 명령행 인터페이스를 쉽게 작성하도록 합니다. 프로그램이 필요한 인자를 정의하면

docs.python.org

 

docs.python.org/ko/3/howto/argparse.html

 

Argparse 자습서 — Python 3.9.0 문서

Argparse 자습서 저자 Tshepang Lekhonkhobe 이 자습서는 파이썬 표준 라이브러리에서 권장하는 명령행 파싱 모듈인 argparse 에 대한 소개입니다. 참고 같은 작업을 수행하는 다른 두 모듈이 있습니다, geto

docs.python.org

 

반응형
반응형

현재 시간, 일시

 

import datetime
 
now = datetime.datetime.now()
print(now)          # 2015-04-19 12:11:32.669083
 
nowDate = now.strftime('%Y-%m-%d')
print(nowDate)      # 2015-04-19
 
nowTime = now.strftime('%H:%M:%S')
print(nowTime)      # 12:11:32
 
nowDatetime = now.strftime('%Y-%m-%d %H:%M:%S')
print(nowDatetime)  # 2015-04-19 12:11:32
반응형
반응형

여러 채널로 오디오 스크립트 작성

transcribe_multichannel.py 

이 페이지에서는 Speech-to-Text를 사용하여 둘 이상의 채널이 포함된 오디오 파일을 텍스트로 변환하는 방법을 설명합니다.

오디오 데이터에는 녹음된 화자에 대한 각각의 채널이 포함되어 있는 경우가 많습니다. 예를 들어 두 사람의 전화 통화를 녹음한 오디오라면 각 회선이 별도로 녹음된 채널 두 개가 포함될 수 있습니다.

여러 채널이 포함된 오디오 데이터를 텍스트로 변환하려면 Speech-to-Text API에 대한 요청에 채널 수를 제공해야 합니다. 요청의 audioChannelCount 필드를 오디오에 있는 채널 수로 설정합니다.

여러 채널이 포함된 요청을 보내면 Speech-to-Text가 오디오에 있는 서로 다른 채널을 식별하는 결과를 반환하며 channelTag 필드를 사용하여 각 결과를 대신하는 항목에 라벨을 지정합니다.

 

오디오 채널 설명 : https://cloud.google.com/speech-to-text/docs/multi-channel

 

여러 채널로 오디오 스크립트 작성  |  Cloud Speech-to-Text 문서  |  Google Cloud

이 페이지에서는 Speech-to-Text를 사용하여 둘 이상의 채널이 포함된 오디오 파일을 텍스트로 변환하는 방법을 설명합니다. 오디오 데이터에는 녹음된 화자에 대한 각각의 채널이 포함되어 있는

cloud.google.com

 

from google.cloud import speech

client = speech.SpeechClient()

with open(speech_file, "rb") as audio_file:
    content = audio_file.read()

audio = speech.RecognitionAudio(content=content)

config = speech.RecognitionConfig(
    encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    language_code="en-US",
    audio_channel_count=2,
    enable_separate_recognition_per_channel=True,
)

response = client.recognize(config=config, audio=audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print("-" * 20)
    print("First alternative of result {}".format(i))
    print(u"Transcript: {}".format(alternative.transcript))
    print(u"Channel Tag: {}".format(result.channel_tag))

 

github.com/googleapis/python-speech/blob/master/samples/snippets/transcribe_multichannel.py

 

googleapis/python-speech

Contribute to googleapis/python-speech development by creating an account on GitHub.

github.com

 

반응형
반응형

google.api_core.exceptions.OutOfRange: 400 Exceeded maximum allowed stream duration of 305 seconds.

"최대 허용 스트림 길이 인 65 초를 초과했습니다."
더 많은 시간 동안 "DEADLINE_SECS"를 수정하려고했지만 작동하지 않았습니다.

 

5 분마다 예외를 포착하는 것은 최적이 아니지만 작동합니다.

 

o think about and already seen in your mom about this is more like a summarizing and reflecting you know back and and the ones were doing studi study the first part was a mobile diary and now a lot of the things we're going to talk about during this interview you have already started to think about and already seen in your mom about this is more like a summarizing and reflecting you know back and and the ones were doing studiTraceback (most recent call last): like how was it for the sweetest person consume that you know and
  File "C:\__STT\env\lib\site-packages\google\api_core\grpc_helpers.py", line 97, in next
    return six.next(self._wrapped)
  File "C:\__STT\env\lib\site-packages\grpc\_channel.py", line 416, in __next__
    return self._next()
  File "C:\__STT\env\lib\site-packages\grpc\_channel.py", line 803, in _next
    raise self
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
        status = StatusCode.OUT_OF_RANGE
        details = "Exceeded maximum allowed stream duration of 305 seconds."
        debug_error_string = "{"created":"@1605234860.496000000","description":"Error received from peer ipv4:216.58.197.234:443","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"Exceeded maximum allowed stream duration of 305 seconds.","grpc_status":11}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "test.py", line 189, in <module>
    main()
  File "test.py", line 185, in main
    listen_print_loop(responses)
  File "test.py", line 124, in listen_print_loop
    for response in responses:
  File "C:\__STT\env\lib\site-packages\google\api_core\grpc_helpers.py", line 100, in next
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.OutOfRange: 400 Exceeded maximum allowed stream duration of 305 seconds.

(env) C:\__STT>
반응형
반응형

ImportError: cannot import name 'enums' from 'google.cloud.speech'  

 

위 에러나서 테스트 안되었는데, 수정되었다고함. enums, types 사용안하면 됨 

 

 

github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types

 

googleapis/python-speech

Contribute to googleapis/python-speech development by creating an account on GitHub.

github.com

(env) C:\__STT>python test.py
Traceback (most recent call last):
  File "test.py", line 35, in <module>
    from google.cloud.speech import enums
ImportError: cannot import name 'enums' from 'google.cloud.speech'

 

 

반응형
반응형

github.com/googleapis/python-speech#windows

 

googleapis/python-speech

Contribute to googleapis/python-speech development by creating an account on GitHub.

github.com

Windows

pip install virtualenv

virtualenv <your-env>

<your-env>\Scripts\activate

<your-env>\Scripts\pip.exe install google-cloud-speech

 

반응형

+ Recent posts