Пример #1
0
def main():
    args = StreamingRecognitionParser().parse_args()

    with audio_open_read(args.audio_file, args.encoding, args.rate, args.num_channels, args.chunk_size,
                         args.pyaudio_max_seconds) as reader:
        stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args))
        metadata = authorization_metadata(args.api_key, args.secret_key, "tinkoff.cloud.stt")
        responses = stub.StreamingRecognize(stt_generate_requests(args, reader), metadata=metadata)
        print_streaming_recognition_responses(responses)
Пример #2
0
def main():
    args = RecognitionParser().parse_args()
    if args.encoding == "RAW_OPUS":
        raise ValueError("RAW_OPUS encoding is not supported by this script")
    stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args.host, args.port))
    metadata = authorization_metadata(args.api_key, args.secret_key,
                                      "tinkoff.cloud.stt")
    response = stub.Recognize(build_recognition_request(args),
                              metadata=metadata)
    print_recognition_response(response)
Пример #3
0
def main():
    args = BaseRecognitionParser().parse_args()
    if args.encoding == stt_pb2.RAW_OPUS:
        raise ValueError("RAW_OPUS encoding is not supported by this script")
    with audio_open_read(args.audio_file, args.encoding, args.rate,
                         args.num_channels, args.chunk_size,
                         args.pyaudio_max_seconds) as reader:
        stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args))
        metadata = authorization_metadata(args.api_key, args.secret_key,
                                          "tinkoff.cloud.stt")
        response = stub.Recognize(build_recognition_request(args, reader),
                                  metadata=metadata)
        print_recognition_response(response)
Пример #4
0
def main():
    args = BaseSynthesisParser().parse_args()
    if args.encoding == tts_pb2.LINEAR16 and args.rate != 48000:
        raise ValueError("LINEAR16 supports only 48kHz for now, use RAW_OPUS")

    with audio_open_write(args.output_file, args.encoding,
                          args.rate) as audio_writer:
        stub = tts_pb2_grpc.TextToSpeechStub(make_channel(args))
        request = build_synthesis_request(args, args.input_text)
        metadata = authorization_metadata(args.api_key, args.secret_key,
                                          "tinkoff.cloud.tts")
        responses = stub.StreamingSynthesize(request, metadata=metadata)
        for stream_response in responses:
            audio_writer.write(stream_response.audio_chunk)
Пример #5
0
def main():
    args = StreamingRecognitionParser().parse_args()

    stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args.host, args.port))
    metadata = authorization_metadata(args.api_key, args.secret_key, "tinkoff.cloud.stt")
    responses = stub.StreamingRecognize(generate_requests(args), metadata=metadata)
    for response in responses:
        for result in response.results:
            print("Channel", result.recognition_result.channel)
            print("Phrase start", result.recognition_result.start_time.ToTimedelta())
            print("Phrase end", result.recognition_result.end_time.ToTimedelta())
            print("Is final", result.is_final)
            for alternative in result.recognition_result.alternatives:
                print("Transcription", alternative.transcript)
                print("Confidence", alternative.confidence)
            print("------------------")
Пример #6
0
def main():
    agi = AGI()
    #agi = None
    if agi != None:
        agi.verbose("EAGI script started...")
        ani = agi.env['agi_callerid']
        uid = agi.env['agi_uniqueid']
        agi.verbose("Call answered from: %s with id %s" % (ani, uid))
    else:
        ani = ""
        uid = str(uuid.uuid4())

    try:
        with dbcon.cursor() as cursor:
            sql = "INSERT INTO calls SET uniqueid=%s,callerid=%s,calldate=NOW()"
            cursor.execute(sql, (uid, ani))
            call_id = cursor.lastrowid
    finally:
        dbcon.commit()

    data = {
        "type": "call",
        "unqueid": uid,
        "callerid": ani[-4:],
        "calldate": time.strftime('%Y-%m-%d %H:%M:%S'),
        "call_id": call_id
    }
    client.publish(cent_channel, data)
    if agi == None:
        ic(data)

    args = StreamingRecognitionParser().parse_args()

    stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args))
    metadata = authorization_metadata(cfg.api_key, cfg.secret_key,
                                      "tinkoff.cloud.stt")
    responses = stub.StreamingRecognize(generate_requests(args, agi),
                                        metadata=metadata)
    save_streaming_recognition_responses(responses, agi, ani, uid, call_id)
Пример #7
0
def main():
    args = BaseRecognitionParser().parse_args()
    total = ''
    if args.encoding == stt_pb2.RAW_OPUS:
        raise ValueError("RAW_OPUS encoding is not supported by this script")
    with audio_open_read(args.audio_file, args.encoding, args.rate,
                         args.num_channels, args.chunk_size,
                         args.pyaudio_max_seconds) as reader:
        stub = stt_pb2_grpc.SpeechToTextStub(make_channel(args))
        metadata = authorization_metadata(args.api_key, args.secret_key,
                                          "tinkoff.cloud.stt")
        response = stub.Recognize(build_recognition_request(args, reader),
                                  metadata=metadata)

        if not isinstance(response, dict):
            # https://developers.google.com/protocol-buffers/docs/proto3#json
            response = MessageToDict(response,
                                     including_default_value_fields=True,
                                     preserving_proto_field_name=True)
        for result in response["results"]:
            for alternative in result["alternatives"]:
                total = total + alternative["transcript"]
    print(total)