示例#1
0
def transcribe_file_with_spoken_punctuation_end_emojis():
    """Transcribe the given audio file with spoken punctuation and emojis enabled."""
    # [START speech_transcribe_spoken_punctuation_emojis_beta]
    from google.cloud import speech_v1p1beta1 as speech
    from google.protobuf import wrappers_pb2

    client = speech.SpeechClient()

    speech_file = "resources/commercial_mono.wav"

    with io.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=8000,
        language_code="en-US",
        # Enable spoken punctuation
        enable_spoken_punctuation=wrappers_pb2.BoolValue(value=True),
        # Enable spoken emojis
        enable_spoken_emojis=wrappers_pb2.BoolValue(value=True),
    )

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

    for i, result in enumerate(response.results):
        alternative = result.alternatives[0]
        print("-" * 20)
        print(u"First alternative of result {}".format(i))
        print(u"Transcript: {}".format(alternative.transcript))
示例#2
0
 def _auto_close_loops(self, close_fiducial_loops, close_odometry_loops,
                       *args):
     """Automatically find and close all loops in the graph."""
     response = self._map_processing_client.process_topology(
         params=map_processing_pb2.ProcessTopologyRequest.Params(
             do_fiducial_loop_closure=wrappers.BoolValue(
                 value=close_fiducial_loops),
             do_odometry_loop_closure=wrappers.BoolValue(
                 value=close_odometry_loops)),
         modify_map_on_server=True)
     print("Created {} new edge(s).".format(len(
         response.new_subgraph.edges)))
示例#3
0
def test_bool_value_write_bool_value():
    class Foo(proto.Message):
        bar = proto.Field(proto.MESSAGE,
            message=wrappers_pb2.BoolValue,
            number=1,
        )
    foo = Foo(bar=True)
    foo.bar = wrappers_pb2.BoolValue()
    assert foo.bar is False
示例#4
0
 def delete_message(self, user, chat, delete_flag=None):
     """ Delete message request """
     response = user.messaging.UpdateMessage(
         RequestUpdateMessage(
             mid=chat.history[0].mid,
             updated_message=MessageContent(deletedMessage=DeletedMessage(
                 is_local=wrappers_pb2.BoolValue(value=delete_flag))),
             last_edited_at=chat.history[0].date))
     return response
示例#5
0
    def delete(self, message: Message or AsyncTask) -> None:
        """Delete message.

        :param message: Message or AsyncTask (in which located Message)
        :return: None
        """
        msg = messaging_pb2.MessageContent(
            deletedMessage=messaging_pb2.DeletedMessage(
                is_local=wrappers_pb2.BoolValue(value=False)))
        self.__update(message, msg)
示例#6
0
 def pod_to_pb_any(value):
     if isinstance(value, bool):
         v = wrappers_pb2.BoolValue(value=value)
     elif isinstance(value, int):
         v = wrappers_pb2.Int32Value(value=value)
     elif isinstance(value, float):
         v = wrappers_pb2.FloatValue(value=value)
     elif isinstance(value, str):
         v = wrappers_pb2.StringValue(value=value)
     else:
         raise ValueError("not supported cell data type: %s" % type(value))
     return v
示例#7
0
 def wrap_value(value):
     if isinstance(value, bool):
         message = wrapper.BoolValue()
         message.value = value
     elif isinstance(value, int):
         message = wrapper.Int64Value()
         message.value = value
     elif isinstance(value, float):
         message = wrapper.DoubleValue()
         message.value = value
     else:
         raise Exception("Unsupported type {}".format(type(value)))
     return message
示例#8
0
def test_enforce_community_memberships_for_user(testing_communities):
    """
    Make sure the user is added to the right communities on signup
    """
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                basic=auth_pb2.SignupBasic(name="testing",
                                           email="*****@*****.**"),
                account=auth_pb2.SignupAccount(
                    username="******",
                    password="******",
                    birthdate="1970-01-01",
                    gender="Bot",
                    hosting_status=api_pb2.HOSTING_STATUS_CAN_HOST,
                    city="Country 1, Region 1, City 2",
                    # lat=8, lng=1 is equivalent to creating this coordinate with create_coordinate(8)
                    lat=8,
                    lng=1,
                    radius=500,
                    accept_tos=True,
                ),
                feedback=auth_pb2.ContributorForm(),
                accept_community_guidelines=wrappers_pb2.BoolValue(value=True),
            ))
    with session_scope() as session:
        email_token = (session.execute(
            select(SignupFlow).where(SignupFlow.flow_token ==
                                     res.flow_token)).scalar_one().email_token)
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(email_token=email_token))
    user_id = res.auth_res.user_id

    # now check the user is in the right communities
    with session_scope() as session:
        w_id = get_community_id(session, "Global")
        c1_id = get_community_id(session, "Country 1")
        c1r1_id = get_community_id(session, "Country 1, Region 1")
        c1r1c2_id = get_community_id(session, "Country 1, Region 1, City 2")

    token = get_session_cookie_token(metadata_interceptor)

    with communities_session(token) as api:
        res = api.ListUserCommunities(communities_pb2.ListUserCommunitiesReq())
        assert [c.community_id
                for c in res.communities] == [w_id, c1_id, c1r1_id, c1r1c2_id]
示例#9
0
    def test_translation_of_search_hit_with_primitives(self):
        """Verify that well-known types get translated into their values rather than into dicts."""

        values_and_serializations = (
            (wrappers_pb2.BoolValue(value=True), True),
            (wrappers_pb2.Int32Value(value=1), 1),
            (wrappers_pb2.UInt32Value(value=2), 2),
            # int64 is expected to be converted to a string because of JSON!!
            (wrappers_pb2.Int64Value(value=3), "3"),
            (wrappers_pb2.StringValue(value="abc"), "abc"),
        )

        for value, expected in values_and_serializations:
            any_proto = any_pb2.Any()
            any_proto.Pack(value)
            self.assertEqual(
                expected,
                response_translation.translate_message_to_dict(any_proto))
示例#10
0
def test_signup_incremental(db):
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(basic=auth_pb2.SignupBasic(
                name="testing", email="*****@*****.**"), ))

    flow_token = res.flow_token
    assert res.flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert res.need_account
    assert res.need_feedback
    assert res.need_verify_email
    assert res.need_accept_community_guidelines

    # read out the signup token directly from the database for now
    with session_scope() as session:
        flow = session.execute(
            select(SignupFlow).where(
                SignupFlow.flow_token == flow_token)).scalar_one()
        assert flow.email_sent
        assert not flow.email_verified
        email_token = flow.email_token

    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(flow_token=flow_token))

    assert res.flow_token == flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert res.need_account
    assert res.need_feedback
    assert res.need_verify_email
    assert res.need_accept_community_guidelines

    # Add feedback
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                flow_token=flow_token,
                feedback=auth_pb2.ContributorForm(
                    ideas="I'm a robot, incapable of original ideation",
                    features="I love all your features",
                    experience="I haven't done couch surfing before",
                    contribute=auth_pb2.CONTRIBUTE_OPTION_YES,
                    contribute_ways=["serving", "backend"],
                    expertise=
                    "I'd love to be your server: I can compute very fast, but only simple opcodes",
                ),
            ))

    assert res.flow_token == flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert res.need_account
    assert not res.need_feedback
    assert res.need_verify_email
    assert res.need_accept_community_guidelines

    # Agree to community guidelines
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                flow_token=flow_token,
                accept_community_guidelines=wrappers_pb2.BoolValue(value=True),
            ))

    assert res.flow_token == flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert res.need_account
    assert not res.need_feedback
    assert res.need_verify_email
    assert not res.need_accept_community_guidelines

    # Verify email
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                flow_token=flow_token,
                email_token=email_token,
            ))

    assert res.flow_token == flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert res.need_account
    assert not res.need_feedback
    assert not res.need_verify_email
    assert not res.need_accept_community_guidelines

    # Finally finish off account info
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                flow_token=flow_token,
                account=auth_pb2.SignupAccount(
                    username="******",
                    password="******",
                    birthdate="1970-01-01",
                    gender="Bot",
                    hosting_status=api_pb2.HOSTING_STATUS_MAYBE,
                    city="New York City",
                    lat=40.7331,
                    lng=-73.9778,
                    radius=500,
                    accept_tos=True,
                ),
            ))

    assert not res.flow_token
    assert res.HasField("auth_res")
    assert res.auth_res.user_id
    assert not res.auth_res.jailed
    assert not res.need_basic
    assert not res.need_account
    assert not res.need_feedback
    assert not res.need_verify_email
    assert not res.need_accept_community_guidelines

    user_id = res.auth_res.user_id

    sess_token = get_session_cookie_token(metadata_interceptor)

    with api_session(sess_token) as api:
        res = api.GetUser(api_pb2.GetUserReq(user=str(user_id)))

    assert res.username == "frodo"
    assert res.gender == "Bot"
    assert res.hosting_status == api_pb2.HOSTING_STATUS_MAYBE
    assert res.city == "New York City"
    assert res.lat == 40.7331
    assert res.lng == -73.9778
    assert res.radius == 500

    with session_scope() as session:
        form = session.execute(select(ContributorForm)).scalar_one()

        assert form.ideas == "I'm a robot, incapable of original ideation"
        assert form.features == "I love all your features"
        assert form.experience == "I haven't done couch surfing before"
        assert form.contribute == ContributeOption.yes
        assert form.contribute_ways == ["serving", "backend"]
        assert form.expertise == "I'd love to be your server: I can compute very fast, but only simple opcodes"
示例#11
0
def _quick_signup():
    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(
                basic=auth_pb2.SignupBasic(name="testing",
                                           email="*****@*****.**"),
                account=auth_pb2.SignupAccount(
                    username="******",
                    password="******",
                    birthdate="1970-01-01",
                    gender="Bot",
                    hosting_status=api_pb2.HOSTING_STATUS_CAN_HOST,
                    city="New York City",
                    lat=40.7331,
                    lng=-73.9778,
                    radius=500,
                    accept_tos=True,
                ),
                feedback=auth_pb2.ContributorForm(),
                accept_community_guidelines=wrappers_pb2.BoolValue(value=True),
            ))

    flow_token = res.flow_token

    assert res.flow_token
    assert not res.HasField("auth_res")
    assert not res.need_basic
    assert not res.need_account
    assert not res.need_feedback
    assert res.need_verify_email

    # read out the signup token directly from the database for now
    with session_scope() as session:
        flow = session.execute(
            select(SignupFlow).where(
                SignupFlow.flow_token == flow_token)).scalar_one()
        assert flow.email_sent
        assert not flow.email_verified
        email_token = flow.email_token

    with auth_api_session() as (auth_api, metadata_interceptor):
        res = auth_api.SignupFlow(
            auth_pb2.SignupFlowReq(email_token=email_token))

    assert not res.flow_token
    assert res.HasField("auth_res")
    assert res.auth_res.user_id
    assert not res.auth_res.jailed
    assert not res.need_basic
    assert not res.need_account
    assert not res.need_feedback
    assert not res.need_verify_email

    user_id = res.auth_res.user_id

    # make sure we got the right token in a cookie
    with session_scope() as session:
        token = (session.execute(
            select(UserSession).join(
                User, UserSession.user_id == User.id).where(
                    User.username == "frodo")).scalar_one()).token
    assert get_session_cookie_token(metadata_interceptor) == token
示例#12
0
def test0(stub: DockerContainerMgrServiceStub):
    bv = wrappers.BoolValue(value=True)
    res = stub.getContainerIds(bv)
    print(res)