- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
package com.example.trynot;
import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Flags.Flag;
import javax.mail.search.FlagTerm;
import com.example.trynot.MainActivity;
import com.example.trynot.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.sax.StartElementListener;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import android.speech.tts.TextToSpeech;
public class MainActivity extends Activity {
private static final int MY_DATA_CHECK_CODE = 1234;
public static Context c,b;
public TextToSpeech tts;
public static Intent serviceIntent;
private static int myNotificationId;
public static class ReadMailSample extends AsyncTask<String,String,Void> implements TextToSpeech.OnInitListener{
Message message;
private TextToSpeech tts;
static String command, phoneNumber, type, priority, name, time_stamp, imei, opt1, opt2, opt3, fromSubString;
Properties properties = null;
private Session session = null;
private Store store = null;
private Folder inbox = null;
String userName="avarote1994@gmail.com" ; // PROVIDE RECEPIENT EMAIL ID
String password="amul11111994" ; // PROVIDE RECEPIENT PASSWORD
static SQLiteDatabase db;
boolean flag=false;
Context acn;
//private Bundle savedInstanceState;
protected Void doInBackground(String...params){ // SEPARATE THREAD TO RUN IN THE BACKGROUND
try{
readMails();
}
catch(Exception e){
Logger logger = Logger.getAnonymousLogger();
logger.log(Level.INFO, "an exception was thrown", e);
}
return null;
}
ReadMailSample(SQLiteDatabase db){
this.db = db;
}
ReadMailSample(){
}
ReadMailSample(Context cn){
acn=cn;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
tts = new TextToSpeech(c,ReadMailSample.this);
}
@Override
protected void onProgressUpdate(String... values) {
try {
System.out.println("---------------------adasd-----------" + time_stamp);
showNotification();
speakOut();
}
catch(Exception e){
e.printStackTrace();
}
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
tts.speak(command, TextToSpeech.QUEUE_FLUSH, null);
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
public void speakOut() {
tts.speak("hello hi", TextToSpeech.QUEUE_FLUSH, null);
}
public void showNotification() {
PendingIntent notificationIntent = preparePendingIntent();
Notification notification = createBasicNotification(notificationIntent);
displayNotification(notification);
}
@SuppressLint("InlinedApi")
private PendingIntent preparePendingIntent() {
Intent intent=new Intent(c,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(
c,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
private Notification createBasicNotification(PendingIntent notificationIntent) {
NotificationCompat.Builder builder = new Builder(c);
long[] vibrationPattern = {0, 200, 800, 200, 600, 200, 400, 200, 200, 200, 100, 200, 50, 200, 50, 200, 50, 200, 50, 200};
Notification notification = builder
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Medication Reminder")
.setContentText(command)
.setAutoCancel(true)
.setContentIntent(notificationIntent)
.setWhen(Calendar.getInstance().getTimeInMillis() + 1000*60+60)
.setVibrate(vibrationPattern)
.build();
return notification;
}
private void displayNotification(Notification notification) {
NotificationManager notificationManager = (NotificationManager)c.getSystemService(Context.NOTIFICATION_SERVICE);
myNotificationId=(int) System.currentTimeMillis();
notificationManager.notify(myNotificationId , notification);
}
public void readMails() throws IOException{
System.out.println("READMAIL hi");
properties = new Properties();
// SETTING UP AN IMAP SERVER TO ACCESS THE RECEPIENT'S EMAIL
properties.setProperty("mail.host", "imap.gmail.com");
properties.setProperty("mail.port", "995");
properties.setProperty("mail.transport.protocol", "imaps");
while(true){// CONTINUOUSLY MONITOR INCOMING MAIL'S
//String cq = "select * from Login4";
//Cursor c = db.rawQuery(cq, null);
// c.moveToFirst();
//final String userName = c.getString(0);
//final String password = c.getString(1);
//String cloud = "avarote1994@gmail.com";
// AUTHENTICATE AND GET AN INSTANCE OF THE SESSION FROM THE SERVER
session = Session.getInstance(properties,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
});
try {
store = session.getStore("imaps");
store.connect();
inbox = store.getFolder("INBOX"); // ACCESS THE INBOX OF THE RECEPIENT'S EMAIL ID
inbox.open(Folder.READ_WRITE); // OPEN THE INBOX IN READ-WRITE MODE
Message messages[] = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false)); //SEARCH INBOX FOR ANY UNREAD MAILS
System.out.println("Number of mails = " + messages.length);
for (int i = 0; i < messages.length; i++) { // PROCESS ALL THE UNREAD MAILS
message = messages[i];
Address[] from = message.getFrom();
String from1 = from[0].toString();
System.out.println(from1);
if(from1.contains("<")){
int start = from1.indexOf("<");
int end = from1.indexOf(">");
fromSubString = from1.substring(start+1,end); // RETRIEVE THE SENDER'S EMAIL ID
} else{
fromSubString = from1;
}
System.out.println(fromSubString);
//if(fromSubString.equals(cloud)){ // CHECK WHETHER THE MAIL IS FROM THE CLOUD
String[] subject = message.getSubject().split(","); // SPLIT THE SUBJECT
System.out.println("hi");
type = subject[0]; // STORE THE DETAILS IN RESPECTIVE VARIABLES
phoneNumber =subject[1];
name = subject[2];
System.out.println(type);
System.out.println(phoneNumber);
System.out.println(name);
//String body=message.getContentType().toString();
// System.out.print(body);
processMessageBody(message);
//System.out.println("--------------------------------");
// }
}
inbox.close(true);
store.close();
}
catch (NoSuchProviderException e) {
e.printStackTrace();
}
catch (MessagingException e) {
e.printStackTrace();
}
}
}
public void processMessageBody(Message message) {
try {
Object content = message.getContent();
String msg=content.toString();
System.out.println(msg);
if (content instanceof Multipart) { // IF MAIL HAS MULTIPART MESSAGE
Multipart multiPart = (Multipart) content;
procesMultiPart(multiPart);
}
else{
System.out.println("Content = "+content);
processSinglepart(content.toString());
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (MessagingException e) {
e.printStackTrace();
}
}
public void processSinglepart(String content){
String[] body = content.split(","); // SPLIT THE CONTENTS OF THE BODY
System.out.println('1');
time_stamp = body[0]; // STORE THE DETAILS IN RESPECTIVE VARIABLES
command = body[3];
System.out.println(time_stamp);
//tts.speak(time_stamp, TextToSpeech.QUEUE_FLUSH, null);
publishProgress(command);
}
public void procesMultiPart(Multipart content) {
System.out.println("amulya");
try {
BodyPart bodyPart = content.getBodyPart(0); // RETRIEVE THE CONTENTS FROM THE BODY
Object o;
o = bodyPart.getContent();
if (o instanceof String) {
System.out.println("Content Multipart= "+o.toString());
processSinglepart(o.toString());
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (MessagingException e) {
e.printStackTrace();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
c = this.getApplicationContext();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ReadMailSample rd=new ReadMailSample(getApplicationContext());
System.out.println("hello");
rd.execute();
System.out.println("------xvsdfsdfsd---------aefaefa-----------------");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我正在尝试实现文本转语音功能。我收到上述错误。该功能在异步线程中运行。异步线程读取邮件。我想将已读邮件转换为语音。
Logcat:
02-08 21:45:26.009: I/System.out(12947): TESTING
02-08 21:45:26.709: I/System.out(12947): javax.mail.internet.MimeMultipart@21cdab10
02-08 21:45:26.709: I/System.out(12947): amulya
02-08 21:45:27.279: I/System.out(12947): Content Multipart= 1221235487821,ad:af:12:2a:d5:c8,High,IT IS THURSDAY TAKE TABLETS,future
02-08 21:45:27.279: I/System.out(12947): use,future use,future use
02-08 21:45:27.279: I/System.out(12947): 1
02-08 21:45:27.279: I/System.out(12947): 1221235487821
02-08 21:45:27.279: I/System.out(12947): ---------------------adasd-----------1221235487821
02-08 21:45:27.299: W/TextToSpeech(12947): speak failed: TTS engine connection not fully set up
02-08 21:45:29.689: D/dalvikvm(12947): GC_FOR_ALLOC freed 455K, 19% free 5727K/7068K, paused 7ms, total 7ms
02-08 21:45:30.499: I/System.out(12947): Number of mails = 0
02-08 21:45:36.029: I/System.out(12947): Number of mails = 0
最佳答案
我已经通过语音解决了这个问题
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import java.util.HashMap;
import java.util.Locale;
public class Speecher implements TextToSpeech.OnInitListener {
private static final String TAG = "TextToSpeechController";
private TextToSpeech myTTS;
private String textToSpeak;
private Context context;
private static Speecher singleton;
public static Speecher getInstance(Context ctx) {
if (singleton == null)
singleton = new Speecher(ctx);
return singleton;
}
private Speecher(Context ctx) {
context = ctx;
}
public void speak(String text) {
textToSpeak = text;
if (myTTS == null) {
// currently can\'t change Locale until speech ends
try {
// Initialize text-to-speech. This is an asynchronous operation.
// The OnInitListener (second argument) is called after
// initialization completes.
myTTS = new TextToSpeech(context, this);
} catch (Exception e) {
e.printStackTrace();
}
}
sayText();
}
public void onInit(int initStatus) {
if (initStatus == TextToSpeech.SUCCESS) {
if (myTTS.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_AVAILABLE)
myTTS.setLanguage(Locale.UK);
myTTS.setPitch((float) 0.9);
}
// status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
if (initStatus == TextToSpeech.SUCCESS) {
int result = myTTS.setLanguage(Locale.UK);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e(TAG, "TTS missing or not supported (" + result + ")");
// Language data is missing or the language is not supported.
// showError(R.string.tts_lang_not_available);
} else {
// Initialization failed.
Log.e(TAG, "Error occured");
}
}
}
private void sayText() {
HashMap<String, String> myHash = new HashMap<String, String>();
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "done");
String[] splitspeech = this.textToSpeak.split("\\\\");
for (int i = 0; i < splitspeech.length; i++) {
if (i == 0) { // Use for the first splited text to flush on audio stream
myTTS.speak(splitspeech[i].toString().trim(), TextToSpeech.QUEUE_FLUSH, myHash);
} else { // add the new test on previous then play the TTS
myTTS.speak(splitspeech[i].toString().trim(), TextToSpeech.QUEUE_ADD, myHash);
}
myTTS.playSilence(100, TextToSpeech.QUEUE_FLUSH, null);
}
}
public void stopTTS() {
if (myTTS != null) {
myTTS.shutdown();
myTTS.stop();
myTTS = null;
}
}
}
从任何地方调用方法...Speecher.getInstance(getApplicationContext()).speak(YOUR_TTS_MESSAGE_HERE);
关于java - 通话失败: tts engine connection not fully setup in the TextToSpeech functionality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35272083/
对于 Android 上的新 TextToSpeech 实例,我遇到了 onInit(..) 的意外问题。 我发现的所有代码示例都假定在调用 onOnit(..) 之前将新实例返回给调用者,以便返回值
我试着像这样使用它 int result2 = tts_hebrew.setLanguage(Locale.iw); 但我无法识别为 Locale.iw。 在http://developer.andr
更新:经过一番挖掘,我设法在 Logcat 中找到了一些信息。见底部。 编辑 2:我现在从头开始创建了一个新 Activity 来减少这个问题。它仍然不能正常工作。这是代码: public class
我正在尝试在不同的类中调用 TextToSpeech。这是我的类(class)现在的样子: //MainActivity.java public class MainActivity extends
我正在创建一个涉及短信的 Android 应用程序,其中一个功能是输入时会读出每个字母。我正在使用TextToSpeech。 我让它在一个测试项目中工作,但是当将它集成到我自己的项目中时,我收到一个未
我正在使用 TextToSpeech 向我的联系人中的某人发送短信。我使用一种非常丑陋的方式来做到这一点,因为我需要以一种方式说出所有表达式“发送消息到联系人短信是你好”。最好是像“发送消息”这样的应
我的安卓应用因为这个原因被亚马逊拒绝了。 当电话打进来时,我正在播放这个 TextToSpeech。他们要我停止播放。我该怎么做? 最佳答案 在实现 TextToSpeech 的服务或 Activit
我的应用程序正在调用广播接收器来读取传入的文本消息并大声说出来。我的 Broadcast Receiver 被正确调用,它正确读取文本消息,但是当涉及到 speak() 方法时,它就崩溃了。这是我的代
我有一个刷新的文本,每次都会发生这种情况。 我调用位于另一个具有以下结构的类中的静态方法方法speak(): public class Voc { static TextToSpeech my
由于内存不足的情况(在程序中,而不是程序员),我的应用程序一直在崩溃。 MAT 显示我的 Activity 的副本有时会在屏幕旋转时保留下来,并且唯一使伪造副本保持 Activity 状态的对象是每个
我希望能够将文本中的语音更改为语音 API,例如更改: 从女性到男性的声音。 让声音更清晰 改变语速 如果可能的话,请有人告诉我。谢谢。 最佳答案 您可以通过 addSpeech() 为特定字符串提供
我正在 TextToSpeech 上创建一个应用程序。但是当我试图运行时,它会在下一行抛出异常。 tts.speak(ruleOne, TextToSpeech.QUEUE_ADD, null); H
我正在使用下面的库来实现 TextToSpeech 功能来说话 - 'net.gotev:speech:1.3.1' 现在我需要将所有国家/地区的口音更改为我尝试过的美国英语 - Speech.get
使用 Android TextToSpeech 时,有什么方法可以指定语音的性别,例如 tts.setGender(TextToSpeech.MALE)或 tts.speak("Hello ") ?
@SuppressWarnings("deprecation") private void saveAudio(String text) { HashMap myHashRender = ne
The bounty在2天后过期。这个问题的答案有资格获得+50声望奖励。 Nerdy Bunz希望引起更多关于此问题的注意。 作为一项实验,以及一种迫使我自己了解tts在Android上工作原理的方
我是 Java 新手 我正在尝试使用 TextToSpeech,我有 Referenced libraries还有这个.java code通过具体的例子。 我的Main.java: package m
我需要调用synthesizeToFile来创建一些音频文件,并且我需要知道它何时完成创建所有这些文件,以便通知用户。 我已经阅读了其他问题,但没有找到适合我的问题,或者该问题与 speak 功能相关
我在onUteranceComplete()中连续调用文本转语音speak()方法,当事件发生时。说话方法工作正常,它不断地朗读文本,但我在这段代码中遇到了一个奇怪的问题。 Activity 结束后,
我试图做一些非常简单的事情,或者我认为它是。 在我的蓝牙聊天中,我设置了 public static boolean potato = false; 在我的 MainActivity 的 onCrea
我是一名优秀的程序员,十分优秀!