gpt4 book ai didi

java - 在 listitem click 和 myactivity 在 Tabactivity 中使用该文本时,文本到语音不起作用

转载 作者:行者123 更新时间:2023-11-30 03:24:40 26 4
gpt4 key购买 nike

我有一个动态 ListView ,在单击列表项时,该字符串数组已转换为文本到语音功能,我将该字符串数组存储在一个字符串中,然后只有我转换为文本到语音。

在这里我包括了我的代码..

public class TTSList extends ListActivity implements TextToSpeech.OnInitListener {
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_EDIT=1;

private GinfyDbAdapter mDbHelper;
private SimpleCursorAdapter dataAdapter;
ListView lv;
public Button btnadd1;
private TextToSpeech tts;
String typed1;
public String praystring;
public TextView txtText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tts_list);

lv =(ListView)findViewById(R.id.list);
mDbHelper = new GinfyDbAdapter(this);
btnadd1 = (Button)findViewById(R.id.btnadd);
btnadd1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

createProject();


}

});

mDbHelper.open();
fillData();
registerForContextMenu(getListView());

}

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void fillData() {
mDbHelper.open();
Cursor projectsCursor = mDbHelper.fetchAllProjects1();
//startManagingCursor(projectsCursor);

// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{GinfyDbAdapter.CATEGORY_COLUMN_PRAYERNAME,GinfyDbAdapter.CATEGORY_COLUMN_WDATE};

// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1,R.id.date};


dataAdapter = new SimpleCursorAdapter(
this, R.layout.activity_row2,
projectsCursor,
from,
to,
0);
setListAdapter(dataAdapter);

EditText myFilter = (EditText) findViewById(R.id.myFilter);
myFilter.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
dataAdapter.getFilter().filter(s.toString());
}
});

dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return mDbHelper.fetchProjectByName(constraint.toString());
}
});

tts = new TextToSpeech(this, this);



}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_insert:
createProject();
return true;

}

return super.onMenuItemSelected(featureId, item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.activity_menu_long, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_delete:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteProject1(info.id);
fillData();
return true;
case R.id.menu_edit:
AdapterContextMenuInfo info1 = (AdapterContextMenuInfo) item.getMenuInfo();
Intent i = new Intent(this, TTSprayer.class);
i.putExtra(GinfyDbAdapter.CATEGORY_COLUMN_ID1, info1.id);
startActivityForResult(i, ACTIVITY_EDIT);
return true;
}
return super.onContextItemSelected(item);
}
private void createProject() {
Intent i = new Intent(this, TTSprayer.class);
startActivityForResult(i, ACTIVITY_CREATE);
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);



Cursor Release = mDbHelper.fetchProject1(id);
String Releasename = Release.getString(Release.getColumnIndexOrThrow(GinfyDbAdapter.CATEGORY_COLUMN_GODNAME));
String Releasename1 = Release.getString(Release.getColumnIndexOrThrow(GinfyDbAdapter.CATEGORY_COLUMN_PRAYFOR));
String Releasename2 = Release.getString(Release.getColumnIndexOrThrow(GinfyDbAdapter.CATEGORY_COLUMN_PRAYEEENAME));


List<String> godname = new ArrayList<String>(Arrays.asList(Releasename.split(",")));
List<String> prayfor = new ArrayList<String>(Arrays.asList(Releasename1.split(",")));
List<String> people = new ArrayList<String>(Arrays.asList(Releasename2.split(",")));



for (String temp : godname) {
for (String temp1 : prayfor) {
for (String temp2 : people) {
praystring = temp +" " + temp1 +" "+ temp2 + " ";

}
}
}


typed1 = praystring;

speakOut();


}

@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}

public void onInit(int status) {

if (status == TextToSpeech.SUCCESS) {

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 {
//btnaudioprayer.setEnabled(true);
speakOut();
}

} else {
Log.e("TTS", "Initilization Failed!");
}

}


private void speakOut() {

tts.speak(typed1, TextToSpeech.QUEUE_FLUSH, null);
}




@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}

单击列表中的行时,它必须产生文本到语音的转换,但是现在我没有得到任何转换。

最佳答案

看起来你的 tts 没有初始化。而你的标签。

onCreate 中添加以下内容

   tts = new TextToSpeech(getParent(),TTSList.this);

添加@Override 注解
    @Override
public void onInit(int status)

关于java - 在 listitem click 和 myactivity 在 Tabactivity 中使用该文本时,文本到语音不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18440636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com