TTS: Difference between revisions

From GiderosMobile
No edit summary
m Text replacement - "</source>" to "</syntaxhighlight>"
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<languages />
<!-- GIDEROSOBJ:TTS -->
<!-- GIDEROSOBJ:TTS -->
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]]<br/>
'''Available since:''' Gideros 2018.1<br/>


'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]]<br/>
=== Description ===
'''<translate>Available since</translate>:''' Gideros 2018.1<br/>
 
=== <translate>Description</translate> ===
Enables text to speech on your mobile.
Enables text to speech on your mobile.
<syntaxhighlight lang="lua">
require "tts"
</syntaxhighlight>


=== <translate>Examples</translate> ===
=== Example ===
'''Example'''
<syntaxhighlight lang="lua">
 
<source lang="lua">
require "tts"
require "tts"


Line 23: Line 22:


tts:addEventListener(Event.TTS_ERROR, function(e)
tts:addEventListener(Event.TTS_ERROR, function(e)
  print("TTS Error:"..e.error)
print("TTS Error:"..e.error)
end)
end)


local function stopSpeech()
local function stopSpeech()
  tts:stop()
tts:stop()


  local function resumeSpeech()
local function resumeSpeech()
      tts:speak("It was stopped and has been resumed")
tts:speak("It was stopped and has been resumed")
  end
end


  local timerB=Timer.new(500, 1)
local timerB=Timer.new(500, 1)
  timerB:addEventListener(Event.TIMER, resumeSpeech)
timerB:addEventListener(Event.TIMER, resumeSpeech)
  timerB:start()
timerB:start()
end
end


Line 43: Line 42:


tts:addEventListener(Event.TTS_INIT_COMPLETE, function()
tts:addEventListener(Event.TTS_INIT_COMPLETE, function()
  print("TTS Initialised")
print("TTS Initialised")
  local sentence = "Test "..count..text
local sentence = "Test "..count..text
  tts:setVolume(1)
tts:setVolume(1)
  tts:speak(sentence, tostring(count))
tts:speak(sentence, tostring(count))
  timer:start()
timer:start()
  --count = count + 1
--count = count + 1
end)
end)


Line 54: Line 53:


tts:addEventListener(Event.TTS_UTTERANCE_COMPLETE, function(e)
tts:addEventListener(Event.TTS_UTTERANCE_COMPLETE, function(e)
  print("Utterance:"..e.utteranceId.." state:"..e.state.. " Count: "..count)
print("Utterance:"..e.utteranceId.." state:"..e.state.. " Count: "..count)


  if e.state == "start" then
if e.state == "start" then
      print("started")
print("started")
  elseif e.state == "done" then
elseif e.state == "done" then
      count += 1
count += 1
      local sentence = "test "..count .. text
local sentence = "test "..count .. text
      if count == 2 then
if count == 2 then
        tts:setLanguage("en-US")
tts:setLanguage("en-US")
        tts:speak(sentence.." in British English", tostring(count))
tts:speak(sentence.." in British English", tostring(count))
      elseif count == 3 then
elseif count == 3 then
        tts:setSpeed(0.4)
tts:setSpeed(0.4)
        tts:setPitch(2)
tts:setPitch(2)
        tts:speak("The pitch and speed have been changed", tostring(count))
tts:speak("The pitch and speed have been changed", tostring(count))
      elseif count == 4 and platform == "iOS" then
elseif count == 4 and platform == "iOS" then
        tts:setSpeed(1)
tts:setSpeed(1)
        tts:setPitch(1)
tts:setPitch(1)
        tts:setVolume(0.2)
tts:setVolume(0.2)
        print("volume: "..tts:getVolume())
print("volume: "..tts:getVolume())
        tts:speak("This is quiet", "3")
tts:speak("This is quiet", "3")
        tts:setVolume(1)
tts:setVolume(1)
      elseif count == 4 then -- not iOS
elseif count == 4 then -- not iOS
        count += 1
count += 1
        tts:shutdown()
tts:shutdown()
      elseif count == 5 and platform == "iOS" then
elseif count == 5 and platform == "iOS" then
        tts:setVoice("com.apple.ttsbundle.siri_female_en-GB_premium")
tts:setVoice("com.apple.ttsbundle.siri_female_en-GB_premium")
        tts:speak("A new voice has been selected by the identifier, but it needs to be installed on the device.", tostring(count))
tts:speak("A new voice has been selected by the identifier, but it needs to be installed on the device.", tostring(count))
        print("pitch: "..tts:getPitch()..", speed: "..tts:getSpeed())
print("pitch: "..tts:getPitch()..", speed: "..tts:getSpeed())
        local voices = tts:getVoicesInstalled()
local voices = tts:getVoicesInstalled()
        for i = 1, #voices do
for i = 1, #voices do
            print(voices[i]["language"]..", "..voices[i]["identifier"]..", "..voices[i]["quality"]..", "..voices[i]["name"])
print(voices[i]["language"]..", "..voices[i]["identifier"]..", "..voices[i]["quality"]..", "..voices[i]["name"])
        end
end
      elseif count > 5 then
elseif count > 5 then
        tts:shutdown()
tts:shutdown()
      end
end
  end
end
end)
end)
</source>
</syntaxhighlight>


{|-
{|-
| style="width: 50%; vertical-align:top;"|
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
=== <translate>Methods</translate> ===
<!--
<!--
[[Special:MyLanguage/camera.availableDevices|camera.availableDevices]] ''<translate>Return a list of available devices.</translate>''<br/>
[[camera.availableDevices]] ''returns a list of available devices''<br/>
 
[[camera.start]] ''starts streaming camera pictures to a Texture''<br/>
[[Special:MyLanguage/camera.start|camera.start]] ''<translate>Start streaming camera pictures to a Texture</translate>''<br/>
[[camera.stop]] ''stops camera streaming''<br/>
 
[[Special:MyLanguage/camera.stop|camera.stop]] ''<translate>Stop camera streaming.</translate>''<br/>
-->
-->


| style="width: 50%; vertical-align:top;"|
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
=== <translate>Events</translate> ===
=== Constants ===
 
=== <translate>Constants</translate> ===
 
|}
|}


{{GIDEROS IMPORTANT LINKS}}
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 13:33, 13 July 2023

Supported platforms:
Available since: Gideros 2018.1

Description

Enables text to speech on your mobile.

require "tts"

Example

require "tts"

local platform = application:getDeviceInfo()

--local tts=TTS.new()
local tts = TTS.new("fr", 1, 1)
local count = 1
local text = "This is a fairly long sentence that will test the new TTS engine for Android devices."

tts:addEventListener(Event.TTS_ERROR, function(e)
	print("TTS Error:"..e.error)
end)

local function stopSpeech()
	tts:stop()

	local function resumeSpeech()
		tts:speak("It was stopped and has been resumed")
	end

	local timerB=Timer.new(500, 1)
	timerB:addEventListener(Event.TIMER, resumeSpeech)
	timerB:start()
end

-- stop tts and then resume it
local timer=Timer.new(9000, 1)
timer:addEventListener(Event.TIMER, stopSpeech)

tts:addEventListener(Event.TTS_INIT_COMPLETE, function()
	print("TTS Initialised")
	local sentence = "Test "..count..text
	tts:setVolume(1)
	tts:speak(sentence, tostring(count))
	timer:start()
	--count = count + 1
end)

tts:setVolume(1)

tts:addEventListener(Event.TTS_UTTERANCE_COMPLETE, function(e)
	print("Utterance:"..e.utteranceId.." state:"..e.state.. " Count: "..count)

	if e.state == "start" then
		print("started")
	elseif e.state == "done" then
		count += 1
		local sentence = "test "..count .. text
		if count == 2 then
			tts:setLanguage("en-US")
			tts:speak(sentence.." in British English", tostring(count))
		elseif count == 3 then
			tts:setSpeed(0.4)
			tts:setPitch(2)
			tts:speak("The pitch and speed have been changed", tostring(count))
		elseif count == 4 and platform == "iOS" then
			tts:setSpeed(1)
			tts:setPitch(1)
			tts:setVolume(0.2)
			print("volume: "..tts:getVolume())
			tts:speak("This is quiet", "3")
			tts:setVolume(1)
		elseif count == 4 then -- not iOS
			count += 1
			tts:shutdown()
		elseif count == 5 and platform == "iOS" then
			tts:setVoice("com.apple.ttsbundle.siri_female_en-GB_premium")
			tts:speak("A new voice has been selected by the identifier, but it needs to be installed on the device.", tostring(count))
			print("pitch: "..tts:getPitch()..", speed: "..tts:getSpeed())
			local voices = tts:getVoicesInstalled()
			for i = 1, #voices do
				print(voices[i]["language"]..", "..voices[i]["identifier"]..", "..voices[i]["quality"]..", "..voices[i]["name"])
			end
		elseif count > 5 then
			tts:shutdown()
		end
	end
end)

Methods

Events

Constants