小编Ama*_*ngh的帖子

如何在Android Studio中使用Google Cloud Translation API?

我正在制作一个用于语言翻译的Android应用程序,到目前为止,我已经使用语音识别器意图将语音输入转换为字符串.现在我想将该字符串翻译成另一种语言并使用TTS引擎说出翻译后的文本.我创建了一个单独的translate_test文件供测试使用.我一直在研究并知道Android Studio中需要API密钥.因此,我创建了API密钥并启用了Google Cloud Translation API.现在我正在尝试导入com.google.cloud.translate.Translation我的MainActivity,但是我收到了这个错误:

错误

我需要10个声明点才能让图像显示出来.所以我只能说导入的文件不存在.

我需要有关如何包含云文件的帮助.我一直在网上进行研究,但仍然无法找到有关如何在Android Studio中包含云文件的教程或任何信息.我甚至读过这些文档.我需要帮助,如果有人能给我一些简单的步骤,我会很高兴.

这是我的MainActivity.java文件:

package com.example.aman.translate_test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.google.cloud.translate.Translation;

public class MainActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = (TextView) findViewById(R.id.textView);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aman.translate_test">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-library android:name="com.google.cloud.translate.Translate" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/api_key"/>

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" /> …
Run Code Online (Sandbox Code Playgroud)

java android google-translate android-manifest android-studio

5
推荐指数
1
解决办法
4545
查看次数